Hello,
I am trying to modify a script for posting information from Safari to MarsEdit blog editor. The script works great but I would like to have it end with the MarsEdit post window active. It seems like Applescript 101 but I need some help.
To explain more, the script now executes from the Safari window. I then have to manually switch to MarsEdit to finish up the blog post. Would it be possible to end with the blog post window “on top of” all other windows?
Thanks,
Bryan
Here is the current script.
-- New Post from Safari
--
-- Gets the title, URL, and selected text from the frontmost Safari window
-- and creates a new post window.
--
-- We were going to do more scripts like this for other browsers,
-- but there were serious problems with the scripting support in the first
-- few browsers we tried, so we decided just to go with Safari.
--
-- MarsEdit sample script
-- 31 July 2004 by Brent Simmons
-- Copyright 2004 Ranchero Software
--edited 11/1/2006 BC to fix getSelection()problem for Safari.http://www.macosxhints.com/article.php?story=20050422144207644
on displayErrorMessage(s)
display dialog (s) buttons {"OK"} default button "OK" with icon caution
end displayErrorMessage
global pageURL
global pageTitle
global selectedText
tell application "Safari"
try
set pageURL to URL of document 1
set pageTitle to name of document 1
set selectedText to do JavaScript "unescape(getSelection());" in document 1
on error errorMessage
displayErrorMessage("Can't create a new post because of an error getting information from Safari.") of me
return
end try
end tell
tell application "MarsEdit"
make new post window
tell post window 1
set title to pageTitle
set link to pageURL
-- Create and set the string for the body text
set s to "<a href=\"" & pageURL & "\">" & pageTitle & "</a>"
if selectedText is not "" then
set s to s & ": "" & selectedText & """
end if
set body to s
end tell
end tell