Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

New Safari Copy TinyURL to Clipboard script

edited October 2008 in FastScripts
I got this tinyURL to clipboard script... well I THOUGHT I got it from red sweater but I can't seem to find it anymore at all. I went to the original owners site but I couldn't find any good way of contacting them beyond a link to a forum what has not seen posts since 2005.

Anyways, it just STOPPED WORKING and I have no idea why at all. I couldn't go without because I use it incessantly so I took a look at it and saw that it was written back in 2005 and uses some fairly inefficient methods so I rewrote a lot of it and thought I would share it!!

I am tempted to replace the dialog with a growl pop since I use growl a lot but honestly I wanted to avoid the call to a second app for speed.
Here is the new script below.
Enjoy

(*

Safari Copy TinyURL to Clipboard v 2.0 - 10/15/2008
Original by "Cowboy" Ben Alman - http://benalman.com/
link - http://cowboyscripts.org/applescript/#Safari_Copy_TinyURL_to_Clipboard

v2 by Jonny "theBunnyMan" Narya - http://bunnyman.info
-removed extra JS call
-put shell command in varible
-rewrote shell command to be more effiect
-call tinyurl api url instead of full website
-added no return from tinyurl message

When triggered, this script will get a TinyURL for the
current Safari window's active page, then copy it to
the clipboard. (see www.tinyurl.com for more info)

Recommended for use with FastScripts script menu,
with a hotkey bound to it, for easy access!

*)

tell application "Safari"
try
set currentDocument to the document of window 1
set currentURL to (URL of currentDocument) as string

(* No idea why this is needed so it is removed works with 10.5 & Safari 3 without -JDN
set currentURL to do JavaScript "escape('" & currentURL & "')" in currentDocument
*)

set curlCMD to ¬
"curl --stderr /dev/null \"http://tinyurl.com/api-create.php?url=" & currentURL & "\""

set tinyURL to (do shell script curlCMD)

if tinyURL is not "" then
display dialog "TinyURL copied to clipboard:" & return & return & tinyURL buttons {"Sweet!"} default button 1
set the clipboard to tinyURL
else
display dialog "TinyURL did not return! Sorry!" buttons {"Awww!"} default button 1
end if

on error
return
end try
end tell

Comments

  • Cool! Thanks for sharing. I bet Cowboy would appreciate if you drop a line to him to let him know about the improvements:

    http://benalman.com/

    Daniel
  • Daniel Jalkut said:
    Cool! Thanks for sharing. I bet Cowboy would appreciate if you drop a line to him to let him know about the improvements:

    http://benalman.com/

    Daniel
    I could only fine one email on the site, on the resume to be exact… so I just sent a email out to that ^_^
Sign In or Register to comment.