Upload
yarosi1
View
225
Download
0
Embed Size (px)
Citation preview
8/12/2019 Things Apple Script fdafdsaGuide
1/27
Things AppleScript GuideRevision 14, 2013-02-01
http://www.culturedcode.com/
The basics 4Lists 4
Working with to-dos 6Getting to-dos 6Getting to-dos in a specific list 6Getting project to-dos 6Getting to-dos in a specific area 7Adding new to-dos 7Setting properties for a to do 9
Working with projects 10Getting projects 10Adding new projects 10Setting properties for a project 11
Working with areas 12Getting areas 12Adding new areas 12Setting properties for an area
12
Deleting areas 13Working with contacts 14
Getting contacts 14Adding new contacts 14
Things AppleScript Guide 1
http://www.culturedcode.com/http://www.culturedcode.com/8/12/2019 Things Apple Script fdafdsaGuide
2/27
Getting all to-dos and projects assigned to a contact 14Assigning items to contacts 15Canceling the assignment of contacts 15
Moving items around 16Moving to-dos/projects between lists 16Exception: scheduling to-dos and projects 16Marking to-dos and projects as completed 17Marking to-dos and projects as canceled 17Assigning projects to to-dos 17Assigning areas to projects/to-dos
18
Detaching to-dos/projects from projects/areas 18Deleting to-dos and projects 18
Working with tags 20Getting all available tags 20Creating new tags 20Getting to do/project tags 20Setting tags 21Working with tag hierarchies 21Deleting tags 22
User interface interactions 23Getting current selected to-dos 23Selecting a focus, project, area, or to do 23Editing a to do/project 23
Integration 25Displaying the quick entry panel 25
Things AppleScript Guide 2
8/12/2019 Things Apple Script fdafdsaGuide
3/27
Other actions 26Emptying the trash 26Logging completed items 26
Example scripts
27Importing items from a text file 27
Things AppleScript Guide 3
8/12/2019 Things Apple Script fdafdsaGuide
4/27
The basics
Each predefined list visible in the left panel of Things can be accessed via AppleScript.
Lists
You can access the following lists of Things using their names:
- list Inbox- list Today- list Next- list Scheduled- list Someday- list Projects- list Logbook
- list Trash
They are predefined and you may not create any new lists using the make command.
Each list contains collections of to-dos.
Please note: the sort order of to-dos and projects accessed using to dos and projectscollections corresponds to the UI. For instance:
tellapplication"Things"setinboxToDostoto dosoflist"Inbox" repeatwithinboxToDoininboxToDos --- do something with each inbox to do using inboxToDo variable
endrepeatendtell
tellapplication"Things"setscheduledToDostoto dosoflist"Scheduled" repeatwithscheduledToDoinscheduledToDos --- to-dos get sorted by schedule date - just like in Things UI endrepeat
endtell
Things AppleScript Guide 4
8/12/2019 Things Apple Script fdafdsaGuide
5/27
Things AppleScript Guide 5
8/12/2019 Things Apple Script fdafdsaGuide
6/27
Working with to-dos
Getting to-dos
You can access all to-dos (including projects) defined in Things using the application-level
collection named to dos. You may also use the to dos name:
Getting to-dos in a specific list
Please use the collection to dos of a given list:
Getting project to-dos
You can access all project to-dos using the projects collection named to dos:
tellapplication"Things"repeatwithtoDointo dos --- do something with each to do using toDo variable endrepeatsettodo_thingstoto donamed"Things"
endtell
tellapplication"Things"repeatwithinboxToDointo dosoflist"Inbox" --- do something with each to do using toDo variable endrepeat
endtell
Things AppleScript Guide 6
8/12/2019 Things Apple Script fdafdsaGuide
7/27
Getting to-dos in a specific area
Please use the collection to dos of a given area:
Adding new to-dos
Typically, youll create new items using the standard makeAppleScript command.
You may use the simple syntax to add a new Inbox to do:
You can also specify the container for the new to do immediately. It can be a list, a project, anarea, or a contact:
tellapplication"Things"repeatwithtoDointo dosofproject"Things" --- do something with each to do using toDo variable endrepeat
endtell
tellapplication"Things"repeatwithccToDointo dosofarea"Cultured Code" --- do something with each to do using ccToDo variable endrepeat
endtell
tellapplication"Things"setnewToDotomakenewto do with properties{name:"New to do",due date:current date}
endtell
Things AppleScript Guide 7
8/12/2019 Things Apple Script fdafdsaGuide
8/27
tellapplication"Things"-- adding to dos in listssetnewToDotomakenewto do with properties{name:"New to do",due date:current date} atbeginningoflist"Today"
telllist"Someday" setnewToDotomakenewto do with properties{name:"New to do for someday"} endtell
-- adding to dos in projectssetnewToDotomakenewto do with properties{name:"New Things feature",due date:current date} atbeginningofproject"Things"
tellproject"Things" setnewToDotomakenewto do with properties{name:"New Things feature"} endtell-- adding to dos in areassetnewToDotomakenewto do with properties{name:"New personal to do"} atbeginningofarea"Personal"tellarea"Personal" setnewToDotomakenewto do with properties{name:"New personal to do"} endtell-- adding delegated to dos
setnewToDotomakenewto do with properties{name:"New delegated to do"} atbeginningofcontact"Steve Jobs"tellcontact"Steve Jobs" setnewToDotomakenewto do with properties{name:"New delegated to do"} endtell
endtell
Things AppleScript Guide 8
8/12/2019 Things Apple Script fdafdsaGuide
9/27
Setting properties for a to do
Heres how you can set the properties of a task:
tellapplication"Things"setnewToDotomakenewto do with properties{name:"New to do",due date:current date} atbeginningoflist"Next"setnameofnewToDoto"This task has been renamed" setnotesofnewToDoto"http://www.cultured.com/"&linefeed&"call Werner for more
details" setdue dateofnewToDoto(current date)+7*days setcompletion dateofnewToDotocurrent date settag namesofnewToDoto"Home, Mac"
Things AppleScript Guide 9
8/12/2019 Things Apple Script fdafdsaGuide
10/27
Working with projects
Getting projects
You can access all projects defined in Things using the application-level collection named
projects. You may also use the projects name:
Alternatively, you may also use the to dos collection of Projects list:
Adding new projects
Please use the standard makeAppleScript command. You can use the simple syntax:
...or specify the container - Projects list:
tellapplication"Things"repeatwithprinprojects --- do something with each project using pr variable endrepeatsetpr_thingstoproject"Things"
endtell
tellapplication"Things"repeatwithprinto dosoflist"Projects" --- do something with each project using pr variable endrepeat
endtell
tellapplication"Things"setnewProjecttomakenewproject with properties{name:"New project",notes:"Tiny note"}
endtell
Things AppleScript Guide 10
8/12/2019 Things Apple Script fdafdsaGuide
11/27
Setting properties for a project
Heres how you can set the properties of a project:
tellapplication"Things"setnewProjecttomakenewproject with properties{name:"New project",notes:"Tiny note"}
atbeginningoflist"Projects"--ortelllist"Projects" setnewProjecttomakenewproject with properties{name:"New project",notes:"Tiny note"} endtell
endtell
tellapplication"Things"setnewProjecttomakenewproject with properties{name:"New project"} atbeginningoflist"Projects"setnameofnewProjectto"This project has been renamed" setnotesofnewProjectto"http://www.cultured.com/"&linefeed&"call Werner for more
details" setdue dateofnewProjectto(current date)+7*days setcompletion dateofnewProjecttocurrent date settag namesofnewProjectto"Home, Mac"
Things AppleScript Guide 11
8/12/2019 Things Apple Script fdafdsaGuide
12/27
Working with areas
Getting areas
Areas are accessible using the application-level collection named areas. You may also use
the name of the given area:
Adding new areas
Please use the standard makeAppleScript command:
Setting properties for an area
Heres how you can set the properties of an area:
tellapplication"Things"repeatwitharinareas --- do something with the area using ar variable endrepeatsetar_thingstoarea"Private"
endtell
tellapplication"Things"setnewAreatomakenewarea
with properties{name:"New area",suspended:false}endtell
Things AppleScript Guide 12
8/12/2019 Things Apple Script fdafdsaGuide
13/27
Deleting areas
Please use the standard deleteAppleScript command. It will move the area to Trash.
tellapplication"Things"setnewAreatomakenewareawith properties{name:"New area"}setnameofnewAreato"This area has been renamed" setsuspendedofnewAreatofalse settag namesofnewAreato"Home, Mac"
endtell
tellapplication"Things"setanAreatoareanamed"Area to remove" deleteanArea
endtell
Things AppleScript Guide 13
8/12/2019 Things Apple Script fdafdsaGuide
14/27
Working with contacts
Getting contacts
Your Things contacts are accessible using the application-level collection named contacts.
You may also use the contacts display name:
Adding new contacts
New Things contacts have to be assigned to a given contact from your Address Book right atthe moment of their creation. Thats why youre supposed to use a dedicated command addcontact named with the Address Book name as parameter:
Things will perform an AddressBook search and create a proper contact record correspondingto the address card of Bartlomiej Bargiel from the Address Book.
Getting all to-dos and projects assigned to a contact
Each contact object contains collections of assigned to-dos. Heres how to use them:
tellapplication"Things"repeatwithaContactincontacts --- do something with the contact using the aContact variable endrepeatsetthatsMetocontact"Bartlomiej Bargiel"
endtell
tellapplication"Things"setnewContacttoadd contact named"Bartlomiej Bargiel"
endtell
Things AppleScript Guide 14
8/12/2019 Things Apple Script fdafdsaGuide
15/27
Assigning items to contacts
Please use the contact property of to-dos/projects to assign them to a contact:
Canceling the assignment of contacts
Please use the deletecommand to remove the contact from todos/projects:
tellapplication"Things"setaContacttocontactnamed"My friend"repeatwithaToDointo dosofaContact --- do something with each to do assigned to my friend endrepeat
endtell
tellapplication"Things"setaContacttocontactnamed"Somebody Else"repeatwithaToDointo dosoflist"Today" setcontactofaToDotoaContact endrepeat
endtell
tellapplication"Things"setaContacttocontactnamed"My friend"repeatwithaToDointo dosofaContact deletecontactofaToDo endrepeat
endtell
Things AppleScript Guide 15
8/12/2019 Things Apple Script fdafdsaGuide
16/27
Moving items around
Moving to-dos/projects between lists
The most common operation you perform using the Things UI is moving your activities
between lists.
This can be done using the move command and works for all to-dos and projects. Youll onlyneed to specify the target list to move the to do/project to:
Exception: scheduling to-dos and projects
Moving items to Scheduled list is not supported - Things requires all scheduled actions toget an activation date.
Please use the schedule command to schedule your to dos and projects:
The above script will set the activation date to tomorrow and put the to do to Scheduled listimmediately.
tellapplication"Things"setnewToDotomakenewto do with properties{name:"New to do for today"}atbeginningoflist"Inbox" movenewToDotolist"Today"--- this marks the project as completed setprtoproject"Things" moveprtolist"Logbook"
endtell
tellapplication"Things"settoDoToScheduletofirstto dooflist"Inbox" scheduletoDoToSchedulefor(current date)+1*days
endtell
Things AppleScript Guide 16
8/12/2019 Things Apple Script fdafdsaGuide
17/27
Marking to-dos and projects as completed
You can complete a to do/project by moving it to the Logbook list:
but you may also want it to stay in its current list before it gets logged (see: log completednowcommand) - please use the statusproperty of to-dos and projects then:
Marking to-dos and projects as canceled
Moving a to do to logbook is not enough to mark it as canceled. Please use the statusproperty of a given to do to cancel it:
Assigning projects to to-dos
You can get or set the to-dos project using the project property:
tellapplication"Things"setprtoproject"Things" moveprtolist"Logbook"
endtell
tellapplication"Things"settoDoToCompletetoto donamed"To do to complete" setstatusoftoDoToCompletetocompleted
endtell
tellapplication"Things"settoDoToCanceltoto donamed"To do to cancel" setstatusoftoDoToCanceltocanceled
endtell
Things AppleScript Guide 17
8/12/2019 Things Apple Script fdafdsaGuide
18/27
Assigning areas to projects/to-dos
You can get or set the to do/projects area using the area property:
Detaching to-dos/projects from projects/areas
You can detach an item from its project or area using the standard AppleScript commanddelete:
Deleting to-dos and projects
tellapplication"Things"setaToDotofirstto do setprojectofaToDotoproject"Things"
endtell
tellapplication"Things"setaToDotofirstto do
setareaofaToDotoarea"Private"endtell
tellapplication"Things"--- this will detach the to do from its project setaToDotofirstto doofprojectnamed"Things" deleteprojectofaToDo--- this will detach the project from its area setaProjecttoproject"Things" deleteareaofaProject
endtell
Things AppleScript Guide 18
8/12/2019 Things Apple Script fdafdsaGuide
19/27
The best location for deleted items is: Trash! You can simply use the move command tomove the items to the Things Trash list:
You can use the standard deleteAppleScript command, too:
tellapplication"Things"setaToDotofirstto domoveaToDotolist"Trash"
endtell
tellapplication"Things"setaToDotofirstto do
deleteaToDosetaProjecttofirstproject deleteaProject
endtell
Things AppleScript Guide 19
8/12/2019 Things Apple Script fdafdsaGuide
20/27
Working with tags
Getting all available tags
Application object supports the tags collection which you can use to access all tags defined
in Things:
Creating new tags
Please use the standard makeAppleScript command:
If a tag with the given name already exists, it will be returned.
Getting to do/project tags
You can use stringor tag objectaccessors to access the tags of Things items:
tellapplication"Things"repeatwithaTagintags --- do something with each tag using the aTag variable endrepeat
endtell
tellapplication"Things"setnewTagtomakenewtagwith properties{name:"Home"}
endtell
Things AppleScript Guide 20
8/12/2019 Things Apple Script fdafdsaGuide
21/27
Setting tags
The most convenient way of setting tags for to-dos and projects is to use the tag namesproperty which accepts a comma-separated string of tag names:
Working with tag hierarchies
You can use the parent tag property to set a parent for a given tag:
tellapplication"Things"setaToDotofirstto dooflist"Inbox"--- output: "Home, Mac" - a string! settagNamestotag namesofaToDo--- output: a list of tag objects settagListtotagsofaToDo repeatwithaTagintagList --- do something with each tag endrepeat
endtell
tellapplication"Things"setaToDotofirstto dooflist"Today" settag namesofaToDoto"Home, Mac"
endtell
tellapplication"Things"sethomeTagtotag"Home" setparent tagofhomeTagtotag"Places"
endtell
Things AppleScript Guide 21
8/12/2019 Things Apple Script fdafdsaGuide
22/27
Deleting tags
Please use the standard deleteAppleScript command:
tellapplication"Things"setaTagtotag"to_remove" deleteaTag
endtell
Things AppleScript Guide 22
8/12/2019 Things Apple Script fdafdsaGuide
23/27
User interface interactions
Getting current selected to-dos
You can access all selected to-dos using the application-level collection named selected to
dos:
Selecting a focus, project, area, or to do
In order to display any list, to do, project, area, or contact in the Things UI, please use theshowcommand:
Editing a to do/project
When adding a new to do or project, you may wish to let the user edit its details manually.Please use the editcommand in that case:
tellapplication"Things"repeatwithselectedToDoinselected to dos moveselectedToDotolist"Today" endrepeat
endtell
tellapplication"Things"-- switches to the proper list and selects the given to do in the list of to-dos showto do"Write AppleScript Guide"-- selects the "Things" project in the left Things panel and shows its contents showproject"Things"
endtell
Things AppleScript Guide 23
8/12/2019 Things Apple Script fdafdsaGuide
24/27
tellapplication"Things"setnewTaskToEdittomakenewto do with properties{name:"Please enter name"} atbeginningoflist"Today"-- Things will switch to "Today" list and enter the edit mode
editnewTaskToEdit-- Same with projects setnewProjectToEdittomakenewproject with properties{name:"Please enter name"} atbeginningoflist"Projects" editnewProjectToEdit
endtell
Things AppleScript Guide 24
8/12/2019 Things Apple Script fdafdsaGuide
25/27
Integration
Displaying the quick entry panel
Please use the show quick entry panelcommand to display the Quick Entry panel.
An optional with properties parameter lets you fill the panel with given values:
Instead of the with properties parameter, you can also specify with autofill,which will try to
pre-populate the panel with information from the current application the user is running:
tellapplication"Things"show quick entry panel
endtell
tellapplication"Things"show quick entry panelwith properties {name:"Enter a title for this to do",notes:"Enter a note"}
endtell
tellapplication"Things"show quick entry panelwith autofill yes
endtell
Things AppleScript Guide 25
8/12/2019 Things Apple Script fdafdsaGuide
26/27
Other actions
Emptying the trash
Please use the empty trash command:
Logging completed items
Please use the log completed now command:
tellapplication"Things"empty trash
endtell
tellapplication"Things"log completed now
endtell
Things AppleScript Guide 26
8/12/2019 Things Apple Script fdafdsaGuide
27/27
Example scriptsImporting items from a text file
setmyFileto(choose filewith prompt"Select a file to read:")open for accessmyFile
setfileContentstoreadmyFileusing delimiter{linefeed}
close accessmyFile
tellapplication"Things"repeatwithcurrentLineinreverseoffileContents
setnewToDotomakenewto do with properties{name:currentLine} atbeginningoflist"Next" -- perform some other operations using newToDo
endrepeatendtell