Finder: FileVault-proof "Get selected Finder items"

FileVault-friendly replacement for Tiger’s buggy “Get selected Finder items” Automator action.

If the Finder selection contains FileVault-protected items, Automator’s Finder action “Get selected Finder items” as included in Tiger fails to pass on results Automator can handle further in the workflow. Hence this workaround, which converts any Finder selection to a list of POSIX paths, a format Automator handles well and can pass on to the ensuing action in the workflow.

Use it as a replacement for the default “Get selected Finder items” action whenever you anticipate including FileVault-protected items in a Finder selection input for Automator workflows.

Two caveats:

  1. The good news: if you intend to run the workflow as a Finder plugin, don’t include any version of a “Get selected Finder items” action at the start of your workflow. Workflows running as Finder plugins automatically pass on the Finder selection in a suitable format to the first action of the plugin workflow. This applies whether the selection includes FileVault-protected items or not.

  2. The bad news: infuriatingly, many more of the Automator actions included in Tiger contain bugs that make them break on FileVault-protected items. To routinely avoid those, set up the workflow to immediately copy the selected items out of the FileVault-protected home folder and then process those copies instead of the selected items. To achieve this, put the “Copy Finder items” action directly behind the FileVault-proof “Get selected Finder items” replacement (or as the first action of the workflow if run as a Finder plugin). As the target destination of the copy action, set any location outside the protected home folder, f.i. in the “Shared” folder of the “Users” directory. To have the workflow automatically transfer the processed files back into the protected home folder afterwards, include the “Move Finder items” action at the end and set a folder inside the protected home folder as the target location for the move action.

Refer to the thread “FileVault issues with automating workflows on the Finder selection” at in the “Automator” forum of the MacScripter site for more in-depth discussion, security considerations and a download link for a working sample workflow that uses Preview to scale a batch of FileVault-protected images selected in the Finder.

on run
	script finderSelectionToPosixPaths
		on run
		end run
		on finderSelection()
			tell application "Finder" to get selection
		end finderSelection
		on finderDocListToAliasList(finderDocList)
			set aliasList to {}
			repeat with i in finderDocList
				set end of aliasList to finderDocToAlias(i)
			end repeat
		end finderDocListToAliasList
		on finderDocToAlias(finderDoc)
				tell application "Finder" to get finderDoc as alias
			on error errormsg
				set markerString to "xyzabazyx"
				repeat while errormsg contains markerString
					set markerString to markerString & markerString
				end repeat
				set oldTIDs to AppleScript's text item delimiters
				set AppleScript's text item delimiters to {"\\\""}
				set theLst to text items of errormsg
				set AppleScript's text item delimiters to {markerString}
				set messageWithoutQuotes to theLst as string
				set AppleScript's text item delimiters to {"\""}
				set theLst to text items of messageWithoutQuotes
				set idCounter to 1
				repeat with i in (items 2 thru -4 of theLst)
					if idCounter is 1 then
						set idCounter to 0
							set pathString to i & ":" & pathString
						on error
							set pathString to i
						end try
						set idCounter to 1
					end if
				end repeat
				set AppleScript's text item delimiters to {markerString}
				set theLst to text items of pathString
				set AppleScript's text item delimiters to {"\""}
				set pathString to theLst as string
				set AppleScript's text item delimiters to oldTIDs
					alias pathString
				on error
					alias (pathString & ":")
				end try
			end try
		end finderDocToAlias
		on finderSelectionToPOsixPathList()
		end finderSelectionToPOsixPathList
		on aliasListToPosixPathList(thisAliasList)
			set PosixPathList to {}
			repeat with i in thisAliasList
				set end of PosixPathList to aliasToPosixPath(i)
			end repeat
		end aliasListToPosixPathList
		on aliasToPosixPath(thisAlias)
			POSIX path of thisAlias
		end aliasToPosixPath
	end script
	run script finderSelectionToPosixPaths
end run

No more need for this in Leopard, Apple finally fixed the underlying bug when moving to Mac OS 10.5.