Solution: Create Asana Tasks from "marked text" via "services" on Mac

automation
mac

#1

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:

  1. create an personal access token for the API (https://asana.com/guide/help/api/api#app-language)
  2. open “Automator” on Mac (e.g. via Spotlight)
  3. select “Service”
  4. once created, select “text” and “any application” on the right top
  5. add an action “Run Apple Script” (https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/MakeaSystem-WideService.html)
  6. use my code below as a reference for your own adoption
  7. Save the service e.g. “Create Task at Asana”
  8. 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 :slight_smile:
    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.