Timers like in Quicksilver via AS

Sharing and discussing custom actions for LaunchBar
Post Reply
ludwigschubert
Rank 4
Rank 4
Posts: 285
Joined: Fri Jun 29, 2007 5:54 pm
Location: Germany, Bavaria

Timers like in Quicksilver via AS

Post by ludwigschubert » Sun Jul 29, 2007 6:43 pm

Hello!
Today I first came across timers in QS here:

http://macsparky.wordpress.com/tag/quicksilver/

What I saw made me very jealous ;-), so I decided to throw together a small AS that would do the same for me; only easier.
Unfortunately I'm still a beginner in AS and so I wanted to post it here for others; you can help me make it better and use it for yourself ==> everybody will be happy ;-)


Usage is "<message to display> <time to wait>"
example for <time to wait>: 10s; 2m, 3h or similiar
<message to display> can be more than one word

A big ThankYou to BravoAlpha for his help to encode an URL with python!

The Script is still very basic, but it works:

Code: Select all


-- Display Alert 0.2 for LB

on handle_string(input)
   
   tell application "Finder"
      
      try
         
         -- Hide Launchbar… doesn't seem to work?
         open location "x-launchbar:hide"
         
         set delayword to last word of input
         
         -- Encode message for URL; strip delay time
         do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(unicode(sys.argv[1], \"utf8\"))' " & quoted form of (text 1 thru ((length of input) - ((length of delayword) + 1)) of input)
         set message to result
         
         -- Determine seconds, minutes, hours or days
         set timemultiplier to 1
         if last character of delayword = "m" then set timemultiplier to 60
         if last character of delayword = "h" then set timemultiplier to 60 * 60
         if last character of delayword = "d" then set timemultiplier to 60 * 60 * 24
         set delayvalue to text 1 thru ((length of delayword) - 1) of delayword
         
         -- 'Do' the actual waiting, then display message
         delay delayvalue * timemultiplier
         open location "x-launchbar:large-type?string=" & message
         
      end try
      
   end tell
   
end handle_string



Any comments and/or help would be very appreciated, especially if I overlooked a simpler way to accomplish this!

Also I'd like your opinion on whether LB should have a "run in…" or a "run at…" option like QS seems to have.

regards,
Ludwig
Last edited by ludwigschubert on Fri Aug 03, 2007 1:36 pm, edited 1 time in total.

BravoAlpha
Posts: 11
Joined: Wed Aug 01, 2007 1:12 am

Re: Timers like in Quicksilver via AS

Post by BravoAlpha » Fri Aug 03, 2007 2:20 am

ludwigschubert wrote:Because Launchbar only lets me display text in Large type via an URL, I currently use URI Escape in my Script

I use python for this:

Code: Select all

-- Encode message for URL
do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(unicode(sys.argv[1], "utf8"))' " & quoted form of message
set message to result

ludwigschubert
Rank 4
Rank 4
Posts: 285
Joined: Fri Jun 29, 2007 5:54 pm
Location: Germany, Bavaria

Post by ludwigschubert » Fri Aug 03, 2007 1:38 pm

BravoAlpha, thank you very much - your advice really helped to make things easier for me and others!

regards,
L

Zettt
Rank 2
Rank 2
Posts: 45
Joined: Sat Mar 28, 2009 1:04 pm
Location: Stuttgart
Contact:

Re: Timers like in Quicksilver via AS

Post by Zettt » Mon May 04, 2009 8:25 am

Hi Ludwig,

I would be very pleased if we could throw our two scripts together. I've written a script which display a Large typed Message after a specific delayed time.
My problem is that, LB can't display dialogs when a script should run in the background. (This is your problem, too. But i know a fix for this ;) )

Why i still want us to merge our scripts is because i've written another script which displays a Growl Message after a specific time.

Here's my Display Large Type Script.

Code: Select all

-- Display Alert 1.1 for LB 5 RC2
-- this script displays a large typed message after a given delay time
--
-- originally written by ludwigschubert http://forums.obdev.at/viewtopic.php?f=24&t=615
-- modified by Zettt (http://www.zettt.de) at 2009-05-04
-- thanks to ptujec for providing additional information about changed AppleScript terms
--
-- Usage: Call LaunchBar, Hit Space, Input your message and provied your delay time at the end in "3s", "1m" or "2d" (without quotes)
-- Example: "This is an example message 2s" (without quotes)

-- take string from LaunchBar
on handle_string(message)
   set future_message to message as text
   
   tell application "LaunchBar"
      -- we don't need to talk with LaunchBar from here. But it's nice to have a LaunchBar icon in the following dialogs. :)
      
      -- how much delay do we need?
      set delay_word to last word of message
      
      -- strip away last word of message
      set delay_word_length to length of delay_word
      set message_length to length of future_message
      set future_message to (characters 1 thru (message_length - delay_word_length) of future_message) as string
      
      -- display it in large type
      display in large type future_message after delay delay_word
   end tell
end handle_string
Last edited by Zettt on Mon Jun 01, 2009 12:54 pm, edited 3 times in total.

Zettt
Rank 2
Rank 2
Posts: 45
Joined: Sat Mar 28, 2009 1:04 pm
Location: Stuttgart
Contact:

Re: Timers like in Quicksilver via AS

Post by Zettt » Mon May 04, 2009 8:40 am

lol that was easy.
I posted the modified script. It's working now.

But we still have one problem. When a file exists with the { RunInBackground = YES; } plist LB skips the handle_string method. :(
Last edited by Zettt on Mon May 04, 2009 10:52 am, edited 1 time in total.

halbtuerke
Posts: 14
Joined: Thu Dec 11, 2008 6:00 pm

Re: Timers like in Quicksilver via AS

Post by halbtuerke » Mon May 04, 2009 10:43 am

Your .plist has to look like this

Code: Select all

{
    InputTypes =     (
        NSStringPboardType
    );
    RunInBackground = YES;
}


And you first have to input the text with the "Enter text" action then you can send it to your action and it should work.


Greetings

Zettt
Rank 2
Rank 2
Posts: 45
Joined: Sat Mar 28, 2009 1:04 pm
Location: Stuttgart
Contact:

Re: Timers like in Quicksilver via AS

Post by Zettt » Mon May 04, 2009 10:52 am

Awesome! Thanks!!!

norbert
Objective Development
Objective Development
Posts: 648
Joined: Thu Nov 09, 2006 6:30 pm

Re: Timers like in Quicksilver via AS

Post by norbert » Thu May 14, 2009 1:17 am

Please see this this post regarding potential issues with this "RunInBackground" approach.

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Re: Timers like in Quicksilver via AS

Post by ptujec » Mon Jun 01, 2009 11:08 am

Its now possible without hacks
viewtopic.php?f=24&t=2818

Zettt
Rank 2
Rank 2
Posts: 45
Joined: Sat Mar 28, 2009 1:04 pm
Location: Stuttgart
Contact:

Re: Timers like in Quicksilver via AS

Post by Zettt » Mon Jun 01, 2009 12:56 pm

Updated script.

Improvements:
  • Is now working with new "after delay" syntax. Thanks @ptujec
  • Last word of message is omitted

Post Reply