Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > AppleScript: Safari & opening local documents

AppleScript: Safari & opening local documents
Thread Tools
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Oct 8, 2003, 06:45 AM
 
Hi,

I have a script which is meant to take the front document of SubEthaEdit and open it in Safari.

However I am having problems getting Safari to admit that the file actually exists!

here is my script:

Code:
tell application "SubEthaEdit" if (number of windows) < 1 then display dialog "There are no open subEthaEdit windows." buttons {"OK"} giving up after 1 -- seconds return else set frontDoc to text document of front window if modified of frontDoc is true then set saveReply to display dialog "There are Unsaved Changes! Do you want to Save the source?" buttons {"Cancel", "Save"} default button 2 if button returned of saveReply is "No" then return else save frontDoc end if end if try set theSourcePath to path of frontDoc -- set theFileAlias to frontDoc as alias -- log theSourcePath -- set theFilePath to (POSIX path of frontDoc) on error errorString number errorNumber display dialog "This Document has never been saved to a file- It cannot be used." return end try end if end tell tell application "Safari" --make new document at the beginning of documents --set the URL of the front document to "file:/" & theSourcePath open (theSourcePath as alias) end tell
when I try to run it Script Editor and Safari Claim the file does not exist:

Code:
tell application "SubEthaEdit" count every window of current application 3 get text document of window 1 document "Test.xhtml" get modified of text document "Test.xhtml" false get path of text document "Test.xhtml" "/Users/diggory/Desktop/Test.xhtml" "File /Users/diggory/Desktop/Test.xhtml wasn't found."
does anyone know the right way to get Safari to open a local document?
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Oct 8, 2003, 07:07 AM
 
OK - Got it to work: here is the code in case anyone wanted it:

Code:
tell application "SubEthaEdit" if (number of windows) < 1 then display dialog "There are no open subEthaEdit windows." buttons {"OK"} giving up after 1 -- seconds return -- can't compile nothing! else set frontDoc to text document of front window if modified of frontDoc is true then set saveReply to display dialog "There are Unsaved Changes! Do you want to Save the source?" buttons {"Cancel", "Save"} default button 2 if button returned of saveReply is "No" then return else save frontDoc end if end if try set theSourcePath to path of frontDoc on error errorString number errorNumber display dialog "This Document has never been saved to a file- It cannot be used." return end try end if end tell tell application "Safari" make new document at the beginning of documents set the URL of the front document to "file://" & (theSourcePath as text) end tell
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:14 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2