Here’s another AppleScript: This one puts an xHTML template on the clipboard: Again, remove the Growl parts if you don’t use Growl.
set XHTMLTemplate to "< !DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
”
set the clipboard to the XHTMLTemplate
tell application “GrowlHelperApp”
– notify title “AppleScript Notification” description (noteText as string) icon of application “Script Editor.app”
set myAllNotesList to {”XHTMLTemplateToClipboard”}
register as application “XHTML Template to Clipboard” all notifications myAllNotesList default notifications {”XHTMLTemplateToClipboard”} icon of application “Finder.app”
notify with name “XHTMLTemplateToClipboard” title “XHTML Template 2 Clipboard” description “The XHTML Template has been put on the clipboard” application name “XHTML Template to Clipboard”
end tell”
I never remember to post these scripts which I write and often use onto the web, so that Google can index them.
So in an attempt to solve that, here we go: Here’s an AppleScript that I use often via QuickSilver. It calls Growl so - if you don’t have Growl, remove the growl parts otherwise AppleScript will ask you where GrowlHelperApp is.
set theIP to do shell script "ifconfig | grep 'broadcast' | awk '{print $2}'"
set the clipboard to theIP
tell application "GrowlHelperApp"
set defaultNotification to "Put IP address on Clipboard"
set myAllNotesList to {defaultNotification}
register as application defaultNotification all notifications myAllNotesList default notifications {defaultNotification} icon of application "Finder.app"
notify with name defaultNotification title defaultNotification description "Your IP Address (" & theIP & ") has been put on the clipboard" application name defaultNotification
end tell
(* Use block comments for comments that
occupy more than one line *)
I wish applescript used c-style comments.
I can never remember the format for multi-line comments , and frequently put // instead of — which, of course, causes an error.
I was reading about Speakable Items and QuickTime and made this script
It will allow you to chapterise (add chapters to) the front Movie in QuickTime Player - by voice. Simply move the play head to the appropriate points and say “Chapter” - then when the last chapter has been added say “Finish”.
Requires Panther and QuickTime Pro.
you can get the script into Script Editor by clicking Here
I had another DSL outage this afternoon - the Bayswater exchange seems a little temperamental.
Being a total geek I whipped-up this applescript to alert me when the Network was up again. Simple, but effective…
Of course if your net connection goes down and you want to use it you won’t be able to copy and paste from here - so you’d better copy it now
The script needs to be saved as an “application” and it should “stay open”. (there are options for both of those in Script Editor’s “Save As…” menu item.)
[edit] - I posted the script on MacOSXHints and after a few comments have tweaked the code to be more friendly to users with Proxies and people who listen to iTunes:
on idle
set secondsToWaitBetweenChecks to 120 — 2 Minutes between checks
set availText to “Your Network Connection is now available.”
set unavailText to “The network is still down.”
set hostToCheck to “www.apple.com”
set checkNetScript to “scutil -r ” & hostToCheck
try
set netStatus to do shell script checkNetScript
if netStatus is “Reachable” then
my announceText(availText)
activate
quit
else
– my announceText(unavailText)
end if
on error
display dialog “Could not check the net status this time.” buttons {”OK”} default button 1 giving up after 5 — seconds
end try
return secondsToWaitBetweenChecks
end idle
to announceText(textToSpeak)
tell application “System Events”
– If iTunes is running dip the Audio.
if (exists process “iTunes”) then
tell application “iTunes”
set oldVolume to sound volume
set sound volume to (sound volume * 0.25)
delay 1
say textToSpeak
delay 1
set sound volume to oldVolume
end tell
else
say textToSpeak
end if
– If the User has Salling Clicker show a funky alert.
if (exists process “SEC Helper”) then
tell application “SEC Helper”
show screen message textToSpeak
end tell
else
display dialog textToSpeak
end if
end tell
end announceText
This script will speak a summary of your unread mail in Mac OS X’s Mail application. In Panther’s Mail.app you can have an AppleScript run as part of a rule - so you can effectively have your computer announce who your mail is from and what the subjects are as it arrives - without having to even switch to the Mail app. You can also refine your rule so that the script is only executed for certain Mail Accounts, or whatever criteria you please.
tell application “Mail”
repeat with thisAccount in every account
set thisInBox to mailbox named “INBOX” of thisAccount
set thisUnreadCount to unread count of thisInBox
if thisUnreadCount is not 0 then
set unreadMessages to (messages of thisInBox whose read status is false)
if thisUnreadCount > 1 then
set pluralText to “s”
set verbText to “are”
else
set pluralText to “”
set verbText to “is”
end if
set speechCountText to “There ” & verbText & ” ” & thisUnreadCount & ” message” & pluralText & ” in ” & (name of thisAccount) & “.”
say speechCountText
repeat with i from 1 to number of items in unreadMessages
set thisMessage to item i of unreadMessages
set theSender to sender of thisMessage
set savedTextItemDelimiters to AppleScript’s text item delimiters
try
set AppleScript’s text item delimiters to {”<"}
set realName to (first text item of (theSender as string))
--finally, reset the text item delimiters:
set AppleScript's text item delimiters to savedTextItemDelimiters
on error m number n from f to t partial result p
log ("Error: " & m & number)
--also reset text item delimiters in case of an error:
set AppleScript's text item delimiters to savedTextItemDelimiters
--and resignal the error: error m number n from f to t partial result p
end try
set messageSpeechText to "From: " & realName & ". Title: " & subject of thisMessage
say messageSpeechText
end repeat
end if
end repeat
tell application “Safari”
set frontURL to the URL of the front document
end tell
set newURL to “http://validator.w3.org/check?uri=” & frontURL
tell application “Safari”
set the URL of the front document to newURL
end tell
and then save it as a compiled script, drop it into ~/Library/Scripts/Applications/Safari/
If you have the Script Menu installed [/Applications/AppleScript/Script Menu.menu] then, whenever Safari is the front application, the script menu contains an option to validate the HTML of the front web page. n.b. this will only work for pages that are on a public web-server - it can’t validate local HTML that is not published.