Page 1 of 1

Timers like in Quicksilver via AS

Posted: Sun Jul 29, 2007 6:43 pm
by ludwigschubert
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

Re: Timers like in Quicksilver via AS

Posted: Fri Aug 03, 2007 2:20 am
by BravoAlpha
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

Posted: Fri Aug 03, 2007 1:38 pm
by ludwigschubert
BravoAlpha, thank you very much - your advice really helped to make things easier for me and others!

regards,
L

Re: Timers like in Quicksilver via AS

Posted: Mon May 04, 2009 8:25 am
by Zettt
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

Re: Timers like in Quicksilver via AS

Posted: Mon May 04, 2009 8:40 am
by Zettt
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. :(

Re: Timers like in Quicksilver via AS

Posted: Mon May 04, 2009 10:43 am
by halbtuerke
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

Re: Timers like in Quicksilver via AS

Posted: Mon May 04, 2009 10:52 am
by Zettt
Awesome! Thanks!!!

Re: Timers like in Quicksilver via AS

Posted: Thu May 14, 2009 1:17 am
by norbert
Please see this this post regarding potential issues with this "RunInBackground" approach.

Re: Timers like in Quicksilver via AS

Posted: Mon Jun 01, 2009 11:08 am
by ptujec
Its now possible without hacks
viewtopic.php?f=24&t=2818

Re: Timers like in Quicksilver via AS

Posted: Mon Jun 01, 2009 12:56 pm
by Zettt
Updated script.

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