Easy access to files on your Mac!

I’ve got something working, but it’s wasn’t as straightforward as I’d hoped.

I’ve had to run AppleScript in my action to get it to work on all files on my Mac - with openURL it only seemed to work for files in the Drafts folder. The action below uses the /Documents/ folder on iCloud Drive as the root.

In the syntax definition file, I’ve added a definition:

"f": "drafts://runAction?action=OpenFile&text=[[value]]"

And then I created an script action, called OpenFile:


var file_name = draft.content // Get file name from action
var system = device.systemName; // Check device - will be macOS or iOS

if (system == "macOS"){
	let method = "execute";
	let script = `on execute(file_name)
		tell application "Finder" to open (POSIX path of (path to home folder)) & "Library/Mobile Documents/com~apple~CloudDocs/Documents/" & file_name as POSIX file
		end execute`;
	let runner = AppleScript.create(script);
	runner.execute(method, [file_name])
		}
else {
	url = "shareddocuments://private/var/mobile/Library/Mobile%20Documents/com~apple~CloudDocs/Documents/" + file_name
	app.openURL(url, false)
	}

I’ve not tested extensively but a link in the form:

[[f:my file.ext]]

will open the same file on either iPhone or Mac.

4 Likes