Move project to another folder

Hi there,

I am looking for a possibility to move a project to a folder by using the keyboard. Sth similar exists in OF1 for ipad. Is there a way (built-in or by scripting) to achieve this?

Best regards,

Ralf

There are two ways that I know.

With the project selected, use the movement keys in Organize>Move>Move (Down/Right/Up/Left), e.g. ^⌘↓, ^⌘→, ^⌘↑, and ^⌘←. Outdent the project first if it is nested in a folder, then move it underneath the destination folder, then indent it.

A faster way would be to use this script that I cooked up using some tips from this thread. It asks you for the exact name of the folder (empty or populated) and then moves the project to the top of that folder. Change “beginning of sections of`” to “end of sections of” in the script if you want the project to wind up at the bottom of the folder. Add a shortcut to the script in either FastScripts or LaunchBar and you can launch it from the keyboard.

repeat
	display dialog "To which folder would you like to move this project" default answer "Folder"
	try
		if the text returned of result is not "" then
			set the theFolder to the text returned of the result
			exit repeat
		end if
	on error
		beep
	end try
end repeat

tell application "OmniFocus"
	tell front document
		tell document window 1 -- (first document window whose index is 1)
			set selectedProjects to selected trees of sidebar
		end tell
		repeat with anItem in selectedProjects
			set theProject to value of item 1 of selectedProjects
			move theProject to (beginning of sections of (first folder whose name is theFolder))
		end repeat
	end tell
end tell
1 Like

Thanks TheWart,

this is a step in the right direction.

Although, I was imagining sth that let me choose the folders from an auto-complete (or best guess) list, as they exist in OF2, when I select a project for a task.

I have some nested folders and it is quite painful typing (and mis-typing) all the path to the right folder.

Thanks for you help,

Ralf

I had some fun learning about AppleScript in attempting to meet your request. Here’s what I have so far, with credit given in the script for chunks I borrowed from others. I welcome any corrections to the readily-visible Frankenstein of scripts I have compiled.

I could not determine if autocomplete is possible in AppleScript, so my best effort at the moment is to return a listing of the user’s OmniFocus folders for review before typing in the destination.

Other discussion about this script can be found on this page in the forum.

(*
TheWart
OmniFocus - Move project to folder of choice
VERSION 0.3
March 24, 2015

// THANKS:
Based on ◸ Veritrope.com's excellent script
"OmniFocus - Write Active Project List to Text File"
VERSION 1.02

Project Status, Latest Updates, and Comments Collected at:
http://veritrope.com/code/omnifocus-write-active-project-list-to-text-file

// CHANGELOG:
0.3  Added display of current folder list for more accurate selection of destination
0.2  Added error checking for misspelled (nonexistent) folders
0.1  Initial Release


// RECOMMENDED INSTALLATION INSTRUCTIONS:

FastScripts Installation (Optional, but recommended):
--Download and Install FastScripts from http://www.red-sweater.com/fastscripts/index.html
--Copy script or an Alias to ~/Library/Scripts/Applications/OmniFocus
--Set up your keyboard shortcut in FastScript's preferences
*)


(* 
======================================
// MAIN PROGRAM 
======================================
*)

display dialog "Do you want to view a list of current folders before you name a destination?" buttons {"No", "Yes"} default button 1

-- IF NO FOLDER LIST REQUESTED
if result = {button returned:"No"} then
	-- ASK FOR DESTINATION FOLDER
	repeat
		display dialog "Where would you like to move the selected project?" default answer ""
		try
			if the text returned of result is not "" then
				set the theFolder to the text returned of the result
				exit repeat
			end if
		on error
			beep
		end try
	end repeat
	-- MOVE THE PROJECT
	tell application "OmniFocus"
		tell front document
			tell document window 1 -- (first document window whose index is 1)
				set selectedProjects to selected trees of sidebar
			end tell
			repeat with anItem in selectedProjects
				set theProject to value of item 1 of selectedProjects
				try
					move theProject to (beginning of sections of (first folder whose name is theFolder))
					-- THANKS TO DrJJWMac ON THE OMNI FORUM FOR THIS ERROR CHECK
				on error
					beep
					display dialog "No folder called " & theFolder & " exists."
				end try
			end repeat
		end tell
	end tell
	
	-- IF FOLDER LIST REQUESTED	
else if result = {button returned:"Yes"} then
	-- COLLECT FOLDER NAMES FROM OF DATABASE (◸ Veritrope.com's code here)
	tell application "OmniFocus"
		set list_folders to {}
		set oDoc to default document
		set grab_folders to (name of (flattened folders of oDoc))
		set folder_names to grab_folders
		-- SORT THE LIST 
		set folders_sorted to my simple_sort(folder_names)
		
		-- CONVERT LIST TO TEXT
		set old_delim to AppleScript's text item delimiters
		set AppleScript's text item delimiters to return
		set folders_sorted to folders_sorted as text
		display dialog "Here are your folders: 
" & folders_sorted buttons {"Continue"} default button 1
		-- ASK FOR DESTINATION FOLDER
		repeat
			display dialog "Where would you like to move this project?" default answer "Folder"
			try
				if the text returned of result is not "" then
					set the theFolder to the text returned of the result
					exit repeat
				end if
			on error
				beep
			end try
		end repeat
		-- MOVE THE PROJECT
		tell front document
			tell document window 1 -- (first document window whose index is 1)
				set selectedProjects to selected trees of sidebar
			end tell
			repeat with anItem in selectedProjects
				set theProject to value of item 1 of selectedProjects
				try
					-- CHANGE "BEGINNING" TO "END" HERE IF PREFERENCE
					move theProject to (beginning of sections of (first folder whose name is theFolder))
				on error
					beep
					display dialog "No folder called " & theFolder & " exists."
				end try
			end repeat
		end tell
	end tell
end if

(* 
======================================
// UTILITY SUBROUTINES 
======================================
*)

--SORT SUBROUTINE
on simple_sort(my_list)
	set the index_list to {}
	set the sorted_list to {}
	repeat (the number of items in my_list) times
		set the low_item to ""
		repeat with i from 1 to (number of items in my_list)
			if i is not in the index_list then
				set this_item to item i of my_list as text
				if the low_item is "" then
					set the low_item to this_item
					set the low_item_index to i
				else if this_item comes before the low_item then
					set the low_item to this_item
					set the low_item_index to i
				end if
			end if
		end repeat
		set the end of sorted_list to the low_item
		set the end of the index_list to the low_item_index
	end repeat
	return the sorted_list
end simple_sort
2 Likes

Hi theWart,

you taking a great effort. This is very nice of you to provide this script. It does help me a lot further, thanks. Now, I can copy the project names directly from the list

ralf