"TinyAndTweet" - Connect two applescripts into one

General discussions about LaunchBar

"TinyAndTweet" - Connect two applescripts into one

Postby ptujec » Sun Feb 15, 2009 2:47 pm

I would like to combine the following two applescripts. The first one is for shortening URLs. http://is.gd/iIRg The second is to Update Twitter with LaunchBar. http://is.gd/f3pj

I would like to have the second started automatically after the first on. Plus I would like to have the result of the first one pasted into the second. So I would be able to shorten an URL with "one" action and would only add some words, hit return and see it on Twitter.

1) Select URL with cmd+L and use "Instant Send" ... start writing is.gd
Image

2) Here is the missing link ... some code to send the result to the next action like that ...
Image

Any suggestions?
Last edited by ptujec on Sun Feb 15, 2009 10:26 pm, edited 1 time in total.
ptujec
 
Posts: 240
Joined: Fri Dec 19, 2008 11:36 am

Postby ptujec » Sun Feb 15, 2009 10:26 pm

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
ptujec
 
Posts: 240
Joined: Fri Dec 19, 2008 11:36 am

Re: "TinyAndTweet" - Connect two applescripts into one

Postby ptujec » Thu Jun 04, 2009 9:59 am

Update
worked adjustments by @cometbus into the script
go here for original: http://twitter.com/cometbus/status/2023559489


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
--
-- Supporting function for determining your default browser
-- Taken from http://daringfireball.net/2009/01/applescripts_targetting_safari_or_webkit
-- added truncateString() function and Growl adjustments
-- perl url encode routine - handles IDN and UTF-8 Chars)
-- by @cometbus (→ see http://twitter.com/cometbus/status/2023559489)
--
-- reordered and modified by @ptujec (using is.gd)
-- thx for help w/ keyboard commands @zweigand

-------------------------------------------
-------------------------------------------

on handle_string(longURL)
   
   set shortURL to shortenURL(longURL)
   set the clipboard to shortURL as text
   my growlRegister()
   set longURLDisplay to truncateString(longURL, 30)
   growlNotify(longURLDisplay, 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
   
   set _browser to GetDefaultWebBrowser()
   
   using terms from application "Safari"
      tell application _browser
         set longURL to URL of front document
      end tell
   end using terms from
   
   set shortURL to shortenURL(longURL)
   set the clipboard to shortURL as text
   my growlRegister()
   set longURLDisplay to truncateString(longURL, 30)
   growlNotify(longURLDisplay, 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 GetDefaultWebBrowser()
   set _scpt to "perl -MMac::InternetConfig -le " & ¬
      "'print +(GetICHelper \"http\")[1]'"
   return do shell script _scpt
end GetDefaultWebBrowser

-------------------------------------------

on shortenURL(longURL)
   set escapedURL to urlencode(longURL)
   set cmd to "curl 'http://is.gd/api.php?longurl=" & escapedURL & "'"
   set shortURL to do shell script cmd
   return shortURL
end shortenURL

-------------------------------------------

on urlencode(theText)
   set _scpt to "perl -MURI::Escape -e \"print uri_escape('" & theText & "');\""
   return do shell script _scpt
end urlencode

-------------------------------------------

on truncateString(inString, len)
   if length of inString < len then
      return inString
   else
      return text 1 thru len of inString & "..."
   end if
end truncateString

-------------------------------------------

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(orig_url, short_url)
      
      set growl_description to orig_url & "\n" & "→ " & short_url
      
      tell application "GrowlHelperApp"
         notify with name "Alert" title "URL shortened" description growl_description application name "is.gd"
      end tell
      
   end growlNotify
end using terms from

-------------------------------------------
-------------------------------------------
ptujec
 
Posts: 240
Joined: Fri Dec 19, 2008 11:36 am


Return to LaunchBar General

Who is online

Users browsing this forum: No registered users and 1 guest