Page 1 of 1
Save file as .webarchive
Posted: Mon Jun 20, 2011 11:27 am
by doobox
Hi there,
I have ran into a huge hurdle.
I got to the point in my app, that i need to save the contents of a field as a .webarchive file
I have looked at some .webarchive files created from within safari, and got a pretty big surprise at the contents.
Is there any way to convert a file to .webarchive in livecode..?
Kind Regards
Gary
Re: Save file as .webarchive
Posted: Mon Jun 20, 2011 12:12 pm
by doobox
This looks to be the way to do it in objective-c:
Code: Select all
WebDataSource *dataSource = [[sourceSignatureWebView mainFrame] dataSource];
WebArchive *archive = [[WebArchive alloc]
initWithMainResource:[dataSource mainResource]
subresources:nil
subframeArchives:nil];
[[archive data] writeToURL…
But i don't know how to do this in live code.
Re: Save file as .webarchive
Posted: Mon Jun 20, 2011 4:48 pm
by Klaus
Hi Gary,
this is surely doable!
Looks like a webarchive is a plain UTF encoded XML file with all resources (images etc.)
stored as base64 encoded inside of the XML file.
You only need to to understand and reproduce the webarchive format
Best
Klaus
Re: Save file as .webarchive
Posted: Mon Jun 20, 2011 5:14 pm
by doobox
Apple script is one possible way, and i have located a script that does nearly what is says on the tin.
It needs to be tweaked somewhat for my needs. But is almost right.
Problem is it is stripping the full urls from any image paths, and i cant see why.
first i have saved the contents of a field as an html file.
Then i run this script on the file.
But the webarchive file has stripped urls down to local location.
ie:
http://www.doobox.co.uk/testimage.png
is stripped to:
file:///testimage.png
The Script:
Code: Select all
tell application "Finder"
set format_from to "html"
set format_to to "webarchive"
set sourcePath to (choose folder with prompt "Please select the source directory")
set sig_webAs to (items of folder sourcePath whose name extension is format_from) as alias list
end tell
repeat with i from 1 to number of items in sig_webAs
set this_item to POSIX path of item i of sig_webAs
set sig_xml to do shell script "Textutil -convert " & format_to & space & quoted form of this_item
log sig_xml
end repeat
Re: Save file as .webarchive
Posted: Tue Jun 21, 2011 10:33 am
by doobox
Hi Guys,
I may be putting this project to bed. I will tell you why...
The concept was to allow the user to create new html email signatures from within the app. for OSX.
The format OSX needs for an email signature file is .webarchive
The only way i could find to convert a saved html file to .webarchive file type, was with a shell script "Textutil -convert"
This all worked great apart from the fact that the conversion was taking place on a local file in the app.
So all image paths a user may have included in the html signature were stripped to local references, instead of retaining there real path.
I can see that the html really needs to reside online when the conversion takes place, as done simply in safari, from the save as menu.
I really cant see a suitable way to have the app, make the html live and save it as .webarchive without scripting safari to open and do the work (messy..!)
It did dawn on me this morning... why did Apple not include a way to use HTML signatures in the signature preferences panel.
I think i may have realized why that is not employed in mail app already.
It looked pretty to
http://instagr.am/p/GB0RS/
Thank-you to all that looked and dwelled on this.
Re: Save file as .webarchive
Posted: Wed Jun 22, 2011 12:22 pm
by Mark
Hi,
I don't know what you're trying to do exactly, but if the main point is to send e-mails, I wouldn't use Apple mail for that (not cross-platform). Instead, use an on-line e-mail server and format your e-mails entirely in HTML, including the signature. That way, you can make really neat e-mails while you only need to send some HTML data to a php script on your server. I do this with my newsletters.
Kind regards,
Mark