Two More AppleScripts

Here’s two more AppleScripts I use all the time with some key shortcuts using Red Sweater Software’s FastScripts.

Link as Tiny URL
Just a variation of the “Clipboard to Tiny URL” I posted recently that works with the URL of the frontmost window in Safari instead of the clipboard:

	tell application "Safari"
		set longURL to URL of front document
	end tell

	set cmd to "curl http://tinyurl.com/api-create.php?url=" & longURL
	set shortURL to do shell script cmd
	set the clipboard to shortURL as text
	beep

Open Selected Yojimbo Bookmarks
I use this with Bare Bones Software’s excellent Yojimbo information organizer. What this script does is iterate through the list of selected items in Yojimbo, and open any Bookmark items in your default browser. I bookmark a lot of blog entries and articles in Yojimbo, and often want to open a few of them at once. I use FastScripts to have this run when I press Command-Shift-O.

	set myURLs to {}

	tell application "Yojimbo"
		set selectedItems to the selection

		repeat with currentItem in selectedItems
			if the class of currentItem is bookmark item then
				set myURLs to myURLs & the location of currentItem
			end if
		end repeat
	end tell

	repeat with currentURL in myURLs
		open location currentURL
	end repeat

Download: URLScripts.zip (2kb)

A Couple of Quick AppleScripts

Here’s a couple of quick AppleScripts I use all the time with Red Sweater Software’s excellent FastScripts to add some key shortcuts.

Clipboard to Single Line
This script takes the contents of the clipboard and converts the text to a single line. This is great for copying a street address from a webpage or document and then pasting the result into Google Maps or whatever.

Here’s the source:

	set addressString to the clipboard as string
	set text item delimiters to return
	set textItems to text items of addressString
	set addressString to ""
	repeat with i in textItems
		set addressString to addressString & i & " "
	end repeat
	set the clipboard to addressString

Clipboard to Tiny URL
This script calls tinyurl.com using curl, and turns a long URL on your clipboard into a short one. The contents of the clipboard are replaced with the short URL.

Here’s the source:

	set longURL to the clipboard
	set cmd to "curl http://tinyurl.com/api-create.php?url=" & longURL
	set shortURL to do shell script cmd
	set the clipboard to shortURL as text
	beep

Download ClipboardScripts.zip (4kb)