Skip to content

Instantly share code, notes, and snippets.

@puttiz
Created May 26, 2012 10:46
Show Gist options
  • Save puttiz/2793350 to your computer and use it in GitHub Desktop.
Save puttiz/2793350 to your computer and use it in GitHub Desktop.
Dialog for concentrate
(*
This script is meant to run at the end of a Concentrate activity. It gives you a choice to start another activity, or choose between two activities, or you can choose not to start a new activity. The idea is that you can run a Pause activity after a work activity. This scipt would be run at the end of the work activity. There is a companion script to be run at the end of a break activity, which automatically starts the work activity again. Or you can use this script at the end of a break activity to give you a choice wether or not to start the work activity again.
You only need to change the values in the section MANDATORY CUSTOMIZATIONS and you can make further customization below. The SCRIPT PART contains the code for the script, unless you want to you don't have to make changes there.
This script was created by Rouven, 2009 and is provided for free without any warranty, etc.
*)
---MANDATORY CUSTOMIZATIONS
--- Define the activities - enter the exact names (as they appear in Concentrate) of the two activities that you want to choose between. You must enclose them in quotation marks. If you only want one activity leave activity2 empty by setting it to just two quotation marks: ""
set activity1 to "03 Short Break"
set activity2 to "04 Long Break"
--- OTHER CUSTOMIZATIONS
--- Define the text for the button that does not trigger a new activity
set button3 to "Stop Working"
--- Define the text and title for the Dialog
set dialogText to "What do you want to do now?"
set dialogTitle to "Choose your next step..."
--- Misc.
set giveUp to 360 --- time in seconds before the dialog gives up and dissappears
set errorGiveUp to 90 --- the same for error messages
(*
________________________________________________________________
SCRIPT PART
*)
---set button texts to activity names
set button1 to activity1
set button2 to activity2
--- display dialog with two ore three buttons depending on wether there is an activity2 and capture result
try
tell application "Concentrate"
if activity2 is equal to "" then
set andNow to display dialog dialogText buttons {button1, button3} default button 1 with title dialogTitle with icon 1 giving up after giveUp
else
set andNow to display dialog dialogText buttons {button1, button2, button3} default button 1 with title dialogTitle with icon 1 giving up after giveUp
end if
set nowDo to button returned of andNow
--- tell Concentrate to start concentrating on the chosen activity or end the script if button3 is chosen
try
if nowDo is equal to button1 then
tell activity activity1
concentrate
end tell
else if nowDo is equal to button2 then
tell activity activity2
concentrate
end tell
else
return
end if
--- Error Handling: give a specific error if Concentrate cannot find the chosen activity, otherweise give a generic error.
on error errText number errNumber
if errNumber is -1728 then
display dialog "The activity \"" & nowDo & "\" that you specified in the script does not seem to exist in Concentrate. Perhaps check your spelling?" with title "There was a Problem!" with icon 2 giving up after errorGiveUp
else
display dialog "There was an unexpected problem, the message I got is: " & errText with title "There was a Problem!" with icon 2 giving up after errorGiveUp
end if
end try
end tell
on error errText number errNumber
display dialog "There was an unexpected problem, the message I got is: " & errText with title "There was a Problem!" with icon 2 giving up after errorGiveUp
end try
(*
This script is meant to run at the end of a Concentrate activity. It gives you a choice to start another activity, or choose between two activities, or you can choose not to start a new activity. The idea is that you can run a Pause activity after a work activity. This scipt would be run at the end of the work activity. There is a companion script to be run at the end of a break activity, which automatically starts the work activity again. Or you can use this script at the end of a break activity to give you a choice wether or not to start the work activity again.
You only need to change the values in the section MANDATORY CUSTOMIZATIONS and you can make further customization below. The SCRIPT PART contains the code for the script, unless you want to you don't have to make changes there.
This script was created by Rouven, 2009 and is provided for free without any warranty, etc.
*)
---MANDATORY CUSTOMIZATIONS
--- Define the activities - enter the exact names (as they appear in Concentrate) of the two activities that you want to choose between. You must enclose them in quotation marks. If you only want one activity leave activity2 empty by setting it to just two quotation marks: ""
set activity1 to "01 Pomodoro"
set activity2 to "02 Surfing"
--- OTHER CUSTOMIZATIONS
--- Define the text for the button that does not trigger a new activity
set button3 to "Stop Working"
--- Define the text and title for the Dialog
set dialogText to "What do you want to do now?"
set dialogTitle to "Choose your next step..."
--- Misc.
set giveUp to 360 --- time in seconds before the dialog gives up and dissappears
set errorGiveUp to 90 --- the same for error messages
(*
________________________________________________________________
SCRIPT PART
*)
---set button texts to activity names
set button1 to activity1
set button2 to activity2
--- display dialog with two ore three buttons depending on wether there is an activity2 and capture result
try
tell application "Concentrate"
if activity2 is equal to "" then
set andNow to display dialog dialogText buttons {button1, button3} default button 1 with title dialogTitle with icon 1 giving up after giveUp
else
set andNow to display dialog dialogText buttons {button1, button2, button3} default button 1 with title dialogTitle with icon 1 giving up after giveUp
end if
set nowDo to button returned of andNow
--- tell Concentrate to start concentrating on the chosen activity or end the script if button3 is chosen
try
if nowDo is equal to button1 then
tell activity activity1
concentrate
end tell
else if nowDo is equal to button2 then
tell activity activity2
concentrate
end tell
else
return
end if
--- Error Handling: give a specific error if Concentrate cannot find the chosen activity, otherweise give a generic error.
on error errText number errNumber
if errNumber is -1728 then
display dialog "The activity \"" & nowDo & "\" that you specified in the script does not seem to exist in Concentrate. Perhaps check your spelling?" with title "There was a Problem!" with icon 2 giving up after errorGiveUp
else
display dialog "There was an unexpected problem, the message I got is: " & errText with title "There was a Problem!" with icon 2 giving up after errorGiveUp
end if
end try
end tell
on error errText number errNumber
display dialog "There was an unexpected problem, the message I got is: " & errText with title "There was a Problem!" with icon 2 giving up after errorGiveUp
end try
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment