Project file structure in finder

Hi all,

I use OF2 on Catalina.
I have a script that replicates the list of OF projects in finder as folders and creates callback urls to the related OF project to launch it directly in OF.
I paste the code below because it could be of use to someone maybe. if you have time to check the last part, it would be awesome.
The last part, which is not working, is “inoffensive”, meaning that it does not do anything.
this part fails to rename to " … (archived)" the finder folders that have an omnifocus project reference in finder which no longer exist in Omnifocus (so a project that was synced to the finder but is no longer inside OF)

how to make the script work:

  • Edit the variable mylocation to an existing folder on your machine for the script to work.
  • Use a dedicated folder that does not contain other documents, at first.

1) this flow assumes you will not edit folder comments in this location. File comments are fine.
2) this flow allows you to regroup project folders at will within the target location. as long as the comments of the manually created folders will not contain “OF_Project_ID:”, the flow will run smoothly.
so you can later change the location to somewhere else, and move the new project folders inside any subfolder in that location, and the flow will still work.

on run {input, parameters}
set mylocation to POSIX file "/Users/>>>YOUR NAME HERE<<</OF Project List"
set projectfolder_superscript to "Project - "
tell application "OmniFocus"
	set theperspective to "Projects"
	tell default document
		set Projects_names to name of every flattened project 
		set Projects_ids to id of every flattened project 
		set Projects_status to status of every flattened project 
		set OF_xcallback_open to "\"{\\field{\\*\\fldinst{HYPERLINK”omnifocus:///task/"
		set OF_xcallback to "omnifocus:///task/"
		set OF_xcallback_close to "\"}}\""
		set Projects_list to {}
	end tell
end tell

tell application "Finder"
	set file_list to the entire contents of folder mylocation as list
	set existingfiles_list to {} as list
	set existingprojects_list to {} as list
	repeat with myfile in file_list
		if (comment of myfile starts with "OF_Project_ID:") then
			set fileName to name of myfile
			copy fileName to the end of existingfiles_list
		end if
	end repeat
	repeat with myfile in file_list
		if (comment of myfile starts with "OF_Project_ID:") then
			set mycomment to comment of myfile
			copy (text 15 thru -1 of mycomment) to the end of existingprojects_list
		end if
	end repeat
	---if (count of existingfiles_list) is not 0 then display dialog "existingfiles_list filled, example " & (item 1 of existingfiles_list)
	my unique(Projects_ids)
	my unique(Projects_names)
	my unique(existingfiles_list)
	my unique(existingprojects_list)
	set cleanList to {}
	set archivelist to existingprojects_list
	repeat with item_counter from 1 to count of Projects_ids

		set myprojectid to (item item_counter of Projects_ids) as text
		set myprojectname to (item item_counter of Projects_names)
		if (myprojectid) is not in existingprojects_list then
			---display dialog "processing: " & myprojectid & " " & myprojectname
			make new folder at mylocation with properties {name:(projectfolder_superscript & myprojectname), comment:("OF_Project_ID:" & myprojectid)}
			set mysubfolder to (POSIX path of mylocation) & "/" & projectfolder_superscript & myprojectname

			make new internet location file at (POSIX file mysubfolder) to (OF_xcallback & (item item_counter of Projects_ids)) with properties {name:(myprojectname)}
			set cleanList's end to myprojectid
		end if
	end repeat
	---below we populate correctly the archivelist2 (as of here, copy of existingproject_list), the list of folders to archive because no longer in OF
	set archivelist2 to {} as list
	repeat with myid in archivelist
		if myid is not in cleanList then
			copy myid to the end of archivelist2
		end if
	end repeat
	---display dialog archivelist2
	repeat with i in file_list
		---display dialog (name of i) as string
			if comment of i starts with "OF_Project_ID:" then
				if ((text 15 thru -1 of ((comment of i) as string)) is in archivelist2) then
					---display dialog (comment of i as string) & " - " & (text 15 thru -1 of ((comment of i) as string)) & " - " & name of i
					if (name of i) does not contain " (archived)" then
						set name of i to ((name of i) & " (archived)")
					end if
				end if
			end if
		end try
	end repeat
end tell
end run
on unique(x) ---remove duplicates from x 
set R to {}
repeat with i in x
	if i is not in R then set end of R to i's contents
end repeat
set x to R
end unique
1 Like

Interesting script. I am now creating similar folders manually, so this would be welcome.
I tried it on OF 3.6.4 but it returns a Script Error -1721.

Should it be able to work on OF 3?

No I don’t have OF3 so the fetching of the properties likely should be adapted.

I also discovered that if you save the folders in finder on onedrive some characters that are accepted by the finder are not accepted by onedrive, meaning you cannot sync. I modified the script to get rid of inadmissible characters, will soon update the code in this post too.