While being used to the service of OmniFocus, I wanted to create a task from a marked Text (e.g. in Mail or Browser).
Basically you mark the text, press the right mouse button, select the specific “Service” and the task gets created.
Apparently - once you know how - it is quite easy to create such “Service” via “Automator” so therefore I share my findings. Follow those steps:
- create an personal access token for the API (https://asana.com/guide/help/api/api#app-language)
- open “Automator” on Mac (e.g. via Spotlight)
- select “Service”
- once created, select “text” and “any application” on the right top
- add an action “Run Apple Script” (Mac Automation Scripting Guide: Making a Systemwide Service)
- use my code below as a reference for your own adoption
- Save the service e.g. “Create Task at Asana”
- mark any text, press right mouse button, select “services”, select “Create Task at Asana” → your task should now appear in your tasks with the marked text in the notes of the task
You can also assign a shortcut to this service in OS X via “System Preferences” → “Keyboard” → “Shortcuts”
on run {input, parameters}
set prompt to "Please name the task:"
set dialogResult to display dialog prompt ¬
buttons {"Cancel", "OK"} default button 2 ¬
default answer "task name"
set theProjectTitle to text returned of dialogResult
set url_text to "curl -X \"POST\" \"https://app.asana.com/api/1.0/tasks\" -H \"Authorization: Bearer YOUR_OWN_PERSONAL_ACCESS_TOKEN_HERE" -H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' --data-urlencode \"workspace=YOUR_WORKSPACE_ID_HERE\" --data-urlencode \"assignee=YOUR_USER_ID_HERE\" --data-urlencode \"notes="
set url_text to url_text & input & "\""
set url_text to url_text & " --data-urlencode \"name=" & theProjectTitle & "\""
set response to do shell script url_text
-- display dialog (url_text as text)
-- display dialog (response as text)
end run
Hope this helps.