Skip to content

Instantly share code, notes, and snippets.

@freklov
Created April 1, 2017 17:49
Show Gist options
  • Select an option

  • Save freklov/94a651f1d9aa14e2173eb1283752a084 to your computer and use it in GitHub Desktop.

Select an option

Save freklov/94a651f1d9aa14e2173eb1283752a084 to your computer and use it in GitHub Desktop.
Applescript for Things: Suspend / Resume work areas based upon tags assinged to the work area
# things-set_active_work_area freklov 03/11/2017
# Suspend / Resume work areas based upon tags assinged to the work area
#
set listOfTags to {"All"}
tell application "Things"
# build a list of available tag names
repeat with thingsArea in areas
set textTagNames to tag names of thingsArea
set listOfAreaTags to my splitText(textTagNames, ", ")
repeat with listTagName in listOfAreaTags
if listOfTags does not contain listTagName then
copy listTagName as text to end of listOfTags
end if
end repeat
end repeat
copy "None Areas" to end of listOfTags
# let choose user from a list of tag names
set listTagChoosen to ¬
(choose from list listOfTags ¬
with title ¬
"Work Area Tags" with prompt ¬
"Choose your scope of areas." default items {"All"} ¬
)
# continue if user did not press cancel button
if listTagChoosen is not false then
set textTagChoosen to first item of listTagChoosen
repeat with thingsArea in areas
if textTagChoosen = "All" then
set suspended of thingsArea to false
else if textTagChoosen = "None Areas" then
set suspended of thingsArea to true
else
set textTagNames to tag names of thingsArea
set listOfAreaTags to my splitText(textTagNames, ", ")
set boolSuspendArea to true
repeat with listTagName in listOfAreaTags
if (listTagName as text) = textTagChoosen then
set boolSuspendArea to false
end if
end repeat
set suspended of thingsArea to boolSuspendArea
end if
end repeat
end if
end tell
# source Mac Automation Scripting Guide
# https://developer.apple.com/library/content/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/index.html#//apple_ref/doc/uid/TP40016239-CH56-SW1
on splitText(theText, theDelimiter)
set AppleScript's text item delimiters to theDelimiter
set theTextItems to every text item of theText
set AppleScript's text item delimiters to ""
return theTextItems
end splitText
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment