The magic word is "key commands" ;) Thx @zweigand
Here is the script.
You have to have tweet.scpt (http://is.gd/f3pj) installed to use this one (plus abbreviation "t")
Once again what it does:
1) shortens a URL you pick (I use cmd+L to select and than "Instant Send" it to LaunchBar) /or just run it and it will take the URL in Safaris front window
2) opens tweet.scpt and inserts the shortend URL
Install: Copy&Paste this script into Script Editor and save it to "~/Library/Application Support/LaunchBar/Actions/" as i.g. "tinyandtweet" (I gave it the abbreviation "tt")
- Code: Select all
-- based on http://www.leancrew.com/all-this/2007/11/long-and-shortened-url-scripts/
-- & http://www.leancrew.com/all-this/2009/02/url-shortening-scripts-fixed-i-think/
-- by @drdrang
-- modified by @ptujec (for LaunchBar)
-- thx for help w/ keyboard commands @zweigand
-------------------------------------------
on handle_string(longURL)
set escapedURL to URLescape(longURL)
set cmd to "curl 'http://is.gd/api.php?longurl=" & escapedURL & "'"
set shortURL to do shell script cmd
set the clipboard to shortURL as text
-- if you want to get a Growl notifications just delete "--" in the next lines
-- my growlRegister()
-- growlNotify("URL gekürzt", longURL & "\n" & "→ " & shortURL)
tell application "System Events"
tell application "LaunchBar" to activate
--delay 0.2
keystroke "t"
keystroke " "
keystroke "v" using command down
tell application "LaunchBar" to remain active
end tell
end handle_string
-------------------------------------------
on run
tell application "Safari" -- you can replace Safari with your Standardbrowser
set longURL to URL of front document
end tell
set escapedURL to URLescape(longURL)
set cmd to "curl 'http://is.gd/api.php?longurl=" & escapedURL & "'"
set shortURL to do shell script cmd
set the clipboard to shortURL as text
-- if you want to get a Growl notifications just delete "--" in the next lines
-- my growlRegister()
-- growlNotify("URL gekürzt", longURL & "\n" & "→ " & shortURL)
tell application "System Events"
tell application "LaunchBar" to activate
--delay 0.2
keystroke "t"
keystroke " "
keystroke "v" using command down
tell application "LaunchBar" to remain active
end tell
end run
-------------------------------------------
on URLescape(longURL)
set cmd to "\nfrom urllib import quote\nprint quote(\"\"\"" & longURL & "\"\"\", \"/:\")\n"
return (do shell script "python -c " & (quoted form of cmd))
end URLescape
-------------------------------------------
-- you can delete the rest below if you don't use Growl notifications
using terms from application "GrowlHelperApp"
on growlRegister()
tell application "GrowlHelperApp"
register as application "is.gd" all notifications {"Alert"} default notifications {"Alert"} icon of application "Launchbar.app"
end tell
end growlRegister
on growlNotify(grrTitle, grrDescription)
tell application "GrowlHelperApp"
notify with name "Alert" title grrTitle description grrDescription application name "is.gd"
end tell
end growlNotify
end using terms from