Timer script: Display delayed messages (without hacks)

Sharing and discussing custom actions for LaunchBar
ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Timer script: Display delayed messages (without hacks)

Post by ptujec » Sun May 31, 2009 8:19 pm

***Update: Go down to see the latest version of the script!***

This script gives you large type after a certain amount of time (V2 gives you also a growl notification)
The last word of your input is your delay time (e.g. "3" (seconds by default), "3m" (minutes), "3h" ...)

Paste the code into the empty window of Script Editor and save it with the name of your choice in the LaunchBar Actions Folder ("~/Library/Application Support/LaunchBar/Actions")

V1 (simple large type)

Code: Select all

on handle_string(message)
   tell application "LaunchBar"
      
      -- set time ... it's the last word of your string e.g. 'test 3'
      set delay_time to last word of message
      
      -- display it in large type
      display in large type message after delay delay_time
      
   end tell
end handle_string




V2 (with Growl Notification)

Code: Select all

on handle_string(message)
   tell application "LaunchBar"
      
      -- set time ... it's the last word of your string e.g. 'test 3'
      set delay_time to last word of message
      
      -- display it in large type
      display in large type message after delay delay_time
      
      -- display growl message
      delay delay_time
      my growlRegister()
      my growlNotify("LaunchBarTimer", message)
      
   end tell
end handle_string

-- additional scripting for Growlnotification
using terms from application "GrowlHelperApp"
   on growlRegister()
      tell application "GrowlHelperApp"
         register as application "LaunchBarTimer" all notifications {"Message from the past"} default notifications {"Message from the past"} icon of application "LaunchBar.app"
      end tell
   end growlRegister
   on growlNotify(grrTitle, grrDescription)
      tell application "GrowlHelperApp"
         notify with name "Message from the past" title grrTitle description grrDescription application name "LaunchBarTimer"
      end tell
   end growlNotify
end using terms from
Last edited by ptujec on Tue Aug 11, 2009 11:40 am, edited 4 times in total.

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

Re: Display delayed messages (without hacks) *RC2 needed*

Post by Zettt » Mon Jun 01, 2009 11:53 am

What about integrating this script with the other script?

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

Re: Display delayed messages (without hacks) *RC2 needed*

Post by ptujec » Mon Jun 01, 2009 12:05 pm

Zettt wrote:What about integrating this script with the other script?

What are you missing?

The only thing which is bugging me a bit is that the delay time is displayed. But I don't know the expression to set the string to new_string without last word (yet).

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

Re: Display delayed messages (without hacks) *RC2 needed*

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

I miss to type 1m for 1 minute or 1h for 1 hour instead of calculating the right amount of seconds beforehand. ;)
Oh forgot: I don't like that the Growl script displays a large type message and a Growl notification. Guess we have to find a workaround.
Last edited by Zettt on Mon Jun 01, 2009 12:43 pm, edited 1 time in total.

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

Re: Display delayed messages (without hacks) *RC2 needed*

Post by ptujec » Mon Jun 01, 2009 12:41 pm

Zettt wrote:I miss to type 1m for 1 minute or 1h for 1 hour instead of calculating the right amount of seconds beforehand. ;)

Did you try? Since you can use all that. It just has to be one word e.g. "3m", "1h" ... even "1.5m", "1.5h" works

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

Re: Display delayed messages (without hacks) *RC2 needed*

Post by Zettt » Mon Jun 01, 2009 1:00 pm

See my script on how to omit last word. Seems like we're doing a programming challenge here. :lol:

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

Re: Display delayed messages (without hacks) *RC2 needed*

Post by ptujec » Mon Jun 01, 2009 1:02 pm

Zettt wrote:See my script on how to omit last word. Seems like we're doing a programming challenge here. :lol:

;) not really ... a link to your version would be helpful

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

Re: Display delayed messages (without hacks) *RC2 needed*

Post by Zettt » Mon Jun 01, 2009 1:07 pm

ptujec wrote: a link to your version would be helpful

No problem. Go here.

It's disappointing that i stil have not found how to get it working with Growl notifications using the new syntax. :x

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

Re: Display delayed messages (without hacks) *RC2 needed*

Post by ptujec » Wed Jun 03, 2009 9:52 am

Once again Zettts new without-hacks-version of the script ... so you don't have to jump around to much ;)

Zettt wrote:Updated script.

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


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

majormauser2
Posts: 5
Joined: Thu Sep 17, 2009 2:43 am

Re: Timer script: Display delayed messages (without hacks)

Post by majormauser2 » Sat Sep 19, 2009 7:02 pm

Any way for it to play a sound when completed?

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

Re: Timer script: Display delayed messages (without hacks)

Post by norbert » Sat Oct 31, 2009 7:41 pm

majormauser2 wrote:Any way for it to play a sound when completed?


Note that the display in large type command also has a with sound option where you can specify a sound to be played when the message appears.

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

Re: Timer script: Display delayed messages (without hacks)

Post by ptujec » Sat Oct 31, 2009 8:15 pm

norbert wrote:
majormauser2 wrote:Any way for it to play a sound when completed?


Note that the display in large type command also has a with sound option where you can specify a sound to be played when the message appears.


This is the version I currently use … with sound:

Code: Select all

-------------------------
-- Display Alert 1.2 for LaunchBar 5
-- 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)
--
-- 05/11/09 really minor change by ptujec - just added sound
-------------------------


on handle_string(message)
   
   tell application "LaunchBar"
      
      -- set time ... it's the last word of your string e.g. 'test 3'
      set delay_time to last word of message
      set future_message to message as text
      
      -- strip away last word of message
      set delay_time_length to length of delay_time
      set message_length to length of future_message
      set future_message to (characters 1 thru (message_length - delay_time_length) of future_message) as string
      
      -- display it in large type
      display in large type future_message after delay delay_time with sound "Glass"
      
   end tell
   
end handle_string

gillibrand
Posts: 10
Joined: Tue Dec 29, 2009 7:33 pm

Re: Timer script: Display delayed messages (without hacks)

Post by gillibrand » Sat Jan 16, 2010 8:02 am

I don't think this adds anything over the AppleScript version, but, coincidentally, I've been doing almost the exact same thing with a ruby script. It assumes you have Growl installed (with growlnotify in your PATH). The syntax is "some message <minutes>", e.g., "check laundry 30". You also need to hit shift-enter to get LaunchBar to start it in the background, otherwise it starts Terminal to run the script. (Anyone know how to use "background script launching" as the default?)

Code: Select all

#!/usr/bin/env ruby -wKU

ARGV.join(' ') =~ /(.*?)(\d*)\s*$/

message = $1
mins = $2.to_i

if mins < 1
  `growlnotify "Alarm is Not Set" -m "You must pass this script a number of minutes to wait, \
or a message followed by the minutes. Example: 'Check the laundry 30'"`
  exit 1
end

`growlnotify "Alarm" -m "Your alarm is set for #{mins} minutes."`

# Fork an invisible subprocess so that this process
# can exit right away instead of blocking and waiting
# at the Terminal.
child = fork do
  sleep mins * 60
  now = Time.now.strftime '%I:%M %p'
  `growlnotify "Alarm - #{now}" -m "#{message}" --sticky`
end

Process.detach child

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

Re: Timer script: Display delayed messages (without hacks)

Post by ptujec » Wed Mar 03, 2010 10:35 am

Justin Blanton posted his version with a pretty detailed description on his blog.
http://justinblanton.com/2010/02/launchbar-timer

I'm reposting it here because I think its really nice and clean

Code: Select all

-- http://justinblanton.com/2010/02/launchbar-timer
on handle_string(msg)

    set duration to last word of msg
    set mLength to (count characters of msg)
    set dLength to ((count characters of duration) + 1)
    set reminder to (characters 1 thru (mLength - dLength) of msg) as string

    tell application "LaunchBar"
        display in large type reminder after delay duration
        delay
    end tell

end handle_string

ptavv
Posts: 1
Joined: Sun Apr 18, 2010 10:19 pm

Re: Timer script: Display delayed messages (without hacks)

Post by ptavv » Sun Apr 18, 2010 10:33 pm

Inspired by this post I've written two other scripts people might find useful.

The first one I call "Schedule" -- it works the same way as Remind but the last argument is the *time* at which you want the reminder to display rather than the duration until reminder.

e.g. Cmd-Space - type Schedule - press Space - type "Start making dinner 5:30pm" - press Enter

At 5:30pm you will get a large text alert showing whatever string you put in (note that the am/pm designation *is* required, you must use a colon between hours and minutes, and it does not accept 24 hour time [i.e. 13:30]).

Code: Select all

on handle_string(msg)
   
   set wordCount to count words of msg
   set timeArray to words (wordCount - 1) thru wordCount of msg
   set timeString to item 1 in timeArray & ":" & item 2 in timeArray as string
   
   set duration to (date timeString) - (date (time string of (current date))) & "s" as string
   set mLength to (count characters of msg)
   set dLength to ((count characters of item 1 in timeArray) + (count characters of item 2 in timeArray) + 1)
   set reminder to (characters 1 thru (mLength - dLength) of msg) as string
   
   tell application "LaunchBar"
      display in large type reminder after delay duration
      delay
   end tell
   
end handle_string


The second script is quite a bit more complicated, but what it does is something of a fusion of Remind and Schedule. It will display your reminder every <interval> until <end time>. I call it "Snooze" since it's a lot like the snooze function on an alarm clock.

e.g. Cmd-Space - type Snooze - press Space - type "Are you studying? You should be every 5m until 6:30pm" - press Enter

This will display "Are you studying? You should be" every 5 minutes until 6:30pm (weird!). The way it handles imperfect time divisions is begin alerting you every <interval> (in the example 5 minutes) from execution and then one final time at the end time. All of the reminders will display without a time alert except the last one, which dings so that you know you're through being reminded.

It requires that you use the syntax: <message> every <interval> until <end time>
<interval> can be specified in seconds (30s), minutes (5m), or hours (1h). If you leave off the specifier for duration (s/m/h) it will assume minutes.
<end time> must be specified the same as the above script -- it requires the colon and am/pm and does not accept 24 time.

Code: Select all

on handle_string(msg)
   set wordArray to words of msg
   
   repeat with i from 1 to count words of msg
      if item i in wordArray is "every" then
         set everyNum to i
      else if item i in wordArray is "until" then
         set untilNum to i
      end if
   end repeat
   
   set intervalString to (item (everyNum + 1) in wordArray) as string
   set hourString to item (untilNum + 1) in wordArray as string
   set minString to item (untilNum + 2) in wordArray as string
   
   set reminderLength to -1 as number
   
   repeat with i from 1 to (everyNum - 1)
      set reminderLength to reminderLength + (count characters of item i in wordArray) + 1
   end repeat
   
   set reminder to (characters 1 thru reminderLength of msg) as string
   
   if ("s" is last character in intervalString) or ("m" is last character in intervalString) or ("h" is last character in intervalString) then
      
      set timeMod to last character in intervalString
      set repeatLength to (count characters of intervalString)
      set repeatDelay to (characters 1 thru (repeatLength - 1) of intervalString) as string
      
      if timeMod is "s" then
         set repeatDelay to repeatDelay as number
      else if timeMod is "m" then
         set repeatDelay to repeatDelay * 60 as number
      else if timeMod is "h" then
         set repeatDelay to repeatDelay * 360 as number
      end if
   else
      set repeatDelay to (intervalString * 60) as number
   end if
   
   
   set timeString to hourString & ":" & minString as string
   set totalDuration to (date timeString) - (date (time string of (current date))) as string
   
   set loopNum to (round (totalDuration / repeatDelay) rounding down) as number
   
   repeat with i from 1 to loopNum
      tell application "LaunchBar"
         display in large type reminder after delay (repeatDelay * i)
      end tell
   end repeat
   
   tell application "LaunchBar"
      display in large type reminder after delay totalDuration with sound "Glass"
   end tell
end handle_string


Both of these scripts will fail if you garble the time syntax or the interval syntax, I don't think they can/will do any damage to LaunchBar and I've not built in any way to quit the reminders once you set them (this is important for Snooze). Although quitting LaunchBar and restarting ought to work.

Post Reply