Five Scripts for Safari Beta
Here are five assorted scripts for use with Safari Beta. Each contains different parts and elements that might be useful in creating other scripts that would be useful, as well. Safari URLs and web page information are downloaded and sent to Entourage, iChat and BBEdit for various purposes.
I am very often sending URLs from web pages through email to keep fellow workers abreast of news that I find in my search for DVD news to update the digitallyOBSESSED! DVD Review web site. It was a very simple matter to write a quick script for the Script Menu that enabled this capability from Safari to Entourage. In the same way, I like to send information through iChat to co-workers, so I have two scripts that grab information from Safari and sends them to iChat. One sends the Page Name and URL and the other uses GUI Scripting to copy some selected text. The fourth script is a special little script that I created so that my girlfirend could quickly download the summaries of the ABC soap operas from the TV Guide web site. The last is a BBEdit glossary item and script. To use place the glossary item in the BBEdit Glossary folder. In the same folder place the script that grabs the URL from Safari so that it can be called by the glossary entry.
Two notes: First, if you are a user of Script Editor 2.0 Beta take a look under the Services Menu and you will see the addition of the capability of "Get Result of an AppleScript," "Make New AppleScript," and "Run as AppleScript" which adds several script-related actions to applications that use Services. For example, the scripts below can be selected and "Make New AppleScript" can be selected from Services. Second, the scripts with GUI Scripting require that "Enable access for assistive devices" in the "Universal Access" pane of System Preferences.
Email URL from Safari in Entourage
property emailaddy : ""
if emailaddy is "" then
display dialog "Enter the from email" default answer "" buttons {"Cancel", "OK"} default button 2
copy text returned of result to senderEmail
end if
tell application "Safari"
set t to name of window 1
set s to URL of document 1
end tell
tell application "Microsoft Entourage"
activate
set newTask to make new outgoing message with properties {name:t, content:s, sender:senderEmail}
open newTask
end tell
Send URL from Safari to iChat
tell application "Safari"
set t to name of window 1
set s to URL of document 1
end tell
set the page_info to t & " - " & s
tell application "iChat"
activate
end tell
tell application "System Events"
tell process "iChat"
set the open_windows to the name of every window
if the open_windows is {} then return "no open windows"
set this_window to my choose_window(open_windows)
if this_window is "false" then return "user cancelled"
click menu item this_window of menu "Window" of menu bar 1
delay 1
set value of text field 1 of window this_window to page_info
keystroke return
delay 1
end tell
end tell
on choose_window(open_windows)
tell application "iChat"
activate
set this_window to (choose from list open_windows with prompt "Pick the window to send to:") as string
return this_window
end tell
end choose_window
Send Copied Text from Safari to iChat
tell application "Safari"
activate
end tell
tell application "System Events"
tell process "Safari"
click menu item "Copy" of menu "Edit" of menu bar 1
end tell
end tell
tell application "iChat"
activate
set page_info to the clipboard
end tell
tell application "System Events"
tell process "iChat"
set the open_windows to the name of every window
if the open_windows is {} then return "no open windows"
set this_window to my choose_window(open_windows)
if this_window is "false" then return "user cancelled"
click menu item this_window of menu "Window" of menu bar 1
delay 1
set value of text field 1 of window this_window to page_info
--keystroke return
delay 1
end tell
end tell
on choose_window(open_windows)
tell application "iChat"
activate
set this_window to (choose from list open_windows with prompt "Pick the window to send to:") as string
return this_window
end tell
end choose_window
Get ABC Soap Opera Summary from TV Guide
property soap_URL : "http://www.tvguide.com/soaps/updates/index.asp"
property theSoaps : {"1 - Port Charles", "2 - All My Children", "3 - One Life to Live", "4 - General Hospital"}
set theDay to current date
set theM to month of theDay
set cMonth to my getMonthDay(theM)
set theD to day of theDay
set theY to year of theDay
set dString to cMonth & "/" & theD & "/" & theY as text
set myDialog to choose from list theSoaps with prompt "Which Soap:"
if myDialog is not false then
set bRet to character 1 of item 1 of myDialog
else
display dialog "Cancelled" buttons {"Cancel"} default button 1 with icon stop giving up after 30
end if
if bRet is "1" then
set theSoap to "pc"
else if bRet is "2" then
set theSoap to "all"
else if bRet is "3" then
set theSoap to "one"
else if bRet is "4" then
set theSoap to "gen"
else
display dialog "Not a proper number." buttons {"Cancel"} default button 1 with icon stop giving up after 30
end if
tell application "Safari"
activate
make new document at beginning of documents
set the URL of document 1 to soap_URL & "?soap=" & theSoap & "&soaps_day=" & dString
end tell
on getMonthDay(theM)
set thedefMon to theM
if thedefMon is January then
set defMonAns to 1
else if thedefMon is February then
set defMonAns to 2
else if thedefMon is March then
set defMonAns to 3
else if thedefMon is April then
set defMonAns to 4
else if thedefMon is May then
set defMonAns to 5
else if thedefMon is June then
set defMonAns to 6
else if thedefMon is July then
set defMonAns to 7
else if thedefMon is August then
set defMonAns to 8
else if thedefMon is September then
set defMonAns to 9
else if thedefMon is October then
set defMonAns to 10
else if thedefMon is November then
set defMonAns to 11
else if thedefMon is December then
set defMonAns to 12
end if
return defMonAns
end getMonthDay
on parse_items(page_source, open_tag, close_tag)
set the tag_length to the length of the close_tag
set the item_list to {}
repeat
set the open_tag_offset to the offset of the open_tag in the page_source
if the open_tag_offset is 0 then exit repeat
set the page_source to (text open_tag_offset thru -1 of the page_source)
set the close_tag_offset to the offset of the close_tag in the page_source
set this_item to (text 1 thru (the close_tag_offset + tag_length - 1) of the page_source)
set the end of the item_list to this_item
set the page_source to (text (close_tag_offset + tag_length) thru -1 of the page_source)
end repeat
return item_list
end parse_items
Apply Current URL to BBEdit Selection
Glossary Entry:
<a href="#SCRIPT currentURL.scpt#">#INSERTION##SELECT#</a>
currentURL.scpt
tell application "Safari"
set s to URL of document 1
end tell
return s
Studio Log
Back
|
|