Jump to content

Retrieve a random task from a Things 3 project using Random Utility


Recommended Posts

Hey! Complete beginner here. Been using Alfred for quite some time but just now starting to get into the more advanced workflows. 

 

Basically what I'd like to accomplish is to retrieve all the tasks from a specific project in Things 3 and have Random Utility randomly select one of the tasks. 

 

So far, I've found an AppleScript to retrieve the to-dos from a specific project in Things 3, but I can't seen to get any further.

tell application "Things3"
	repeat with toDo in to dos of project "Things"
		--- do something with each to do using toDo variable
end repeat end tell

What I'd like to do next is output the retrieved to-dos so that Random Utility can randomly select one of the tasks.

 

Any help is appreciated! 

Link to comment

Basically, you need to return a string with the title of a todo on each line. I don't have Things, but if you were getting the titles of every Safari tab, it would look like this:

set _titles to ""
tell application "Safari"
	repeat with _win in windows
		repeat with _tab in _win's tabs
			set _titles to _titles & (name of _tab as text) & "\n"
		end repeat
	end repeat
end tell
return _titles

 

Put that in a Run Script (Language = /usr/bin/osascript (AS)) and connect it to your Random Utility with Random = "Word from list" and Words = "{query}".

Link to comment

Solved it, if anyone else using Things 3 and Alfred who would want to use this AppleScript!

on run
	set theQuery to "{query}"
		set _titles to ""
		tell application "Things3"
			repeat with toDo in to dos of project "Kemi 2"
				set _titles to _titles & (name of toDo as text) & "\n"
			end repeat
		end tell
		return _titles
	return theQuery
end run

Thanks @deanishe for the help!

Link to comment
3 hours ago, oktourist said:

return theQuery

 

Remove this line. It's not correct. But it doesn't do anything anyway because the script finishes after the first return statement and that's the second one. You also don't need the set theQuery ... line because your script doesn't take any input from a previous action.

Edited by deanishe
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...