Sorry to re-address this question after over a week of silence, but 1) I've been out of town and so had limited time to devote to it and 2) have re-coded some of my scripts to include change(s) suggested here.
Those changes have resulted in further problems/questions.
Let me digress just a bit.
Early last week I asked how to select an item on the sidebar from Safari to ensure I was storing a copy of a web-page to a file whose location I could determine. I was using GUI scripting to select a sidebar item that was a folder that I could then later use as part of my script. My objection was that I was using the same script on multiple machines and so hardcoding the name was not an answer.
I have since re-thought that and built a handler such that I pass the folder name to the handler that defines the location in which to save the file.
But this now raises some other issues. If you tell Safari to View Source and save the page, it results in a document with "HTML document" as the kind, and both a creator type and file type as "missing value". This means that I can then double click the saved file's icon and it will open in the default browser (Safari or otherwise).
On the other hand, if I script it (as Ed Stockly and others suggested and as I implemented) this way:
tell application "Safari" to set sourceHTML to source of document 1 --get the doc source into a variable set myfile to WhereToSave & my_Page_Name & ".html" try close access file myfile end try set fileReference to open for access file myfile with write permission --creates the file write (sourceHTML as string) to fileReference starting at eof close access fileReference
it creates a file at location WhereToSave with a name defined by the string contained in the variable my_Page_Name and a qualifier of ".html". This file has a file type of "TEXT" and creator type of "ttxt". While this is sufficient to then open the file and search for the text I want, if I wish to view this file in a browser, I can no longer double click its icon and have it open in a browser; I now have to use a right click and open it with a dialog to pick the browser, otherwise it opens is TextEdit. I can change the creator code to "sfri", but this forces Safari as the browser.
So, question one is this; is there a way to set the file type and creator type of a file to "missing value" once they are set to some other value? I tried to set them both to an empty string (tell app "Finder" to set creator type of file myfile to "") but got an error (don't remember the number or message). What is the value that causes file info to return "missing value" for the creator type and file type?
My next question goes back to picking the folder from a sidebar in a save dialog.
The code is quite extensive so I'll not post it here, but rather give a description of what I'm doing and maybe it will explain what I'm trying to do.
I have a script that currently works under Tiger on a G4 Power PC machine that I'm also trying to make work on an Intel based machine running OS X 10.6.2. The script navigates through several web pages (on Fidelity's website) to the page I want to print. I'm using GUI scripting to get to the specific page I want. I then tell Safari to print the page (I want it in it's formatted form) and select "View with Preview" as the selection in the print dialog.
This causes Preview to open the document where I then use GUI scripting to tell Preview to save the file, change the default name to a name that includes the date and (the key part) picks the location from the sidebar. This all works wonderfully on Tiger. It falls apart under Snow Leopard trying to pick the location from the sidebar.
Preview is not scriptable (at least it doesn't have a dictionary). So I'm using GUI scripting. Is there another way to do this? If not, I still need a way, through GUI scripting, to pick an item from the sidebar under Snow Leopard.
Sorry for the length of this.
All help is greatly appreciated. I'm still a newbie when it comes to Applescript, even though I've dabbled at it for years. The people in this forum are a Godsend to us who only occasionally play around with it.
Jim Brandt
|