Easy access to files on your Mac!

I played around with your sample code and managed to get it working in macOS and iOS with some slight modifications and enhancements (leveraging template tags to specify preferred root folders).

I’ll publish the action tomorrow or over the weekend once I work out some good documentation for it but thanks for pointing me in the right direction.

For reference

let fileName = draft.content // Get file name from action
let system = device.systemName; // Check device - will be macOS or iOS
let rootPath = "";
if (system === "macOS"){
    let rootPath = draft.getTemplateTag("macOS-root-path");
    if (rootPath == null || rootPath.trim().length == 0) {
        context.fail("Template Tag 'macOS-root-path'. Typically this is defined in the previous step of this action");
    }
    let fullPath = `${rootPath}/${fileName}`;
    let method = "execute";
    let script = `on execute(full_path)
    tell application "Finder" to open full_path as POSIX file
    end execute`;
    let runner = AppleScript.create(script);
    if (!runner.execute(method, [fullPath])) {
        alert(`Could not open file '${fullPath}' because of: \n` + runner.lastError);
        context.fail(`Unable to open file '${fullPath}'`);
    }
}
else {
    rootPath = draft.getTemplateTag("iOS-root-path");
    if (rootPath == null || rootPath.trim().length == 0) {
        context.fail("Template Tag 'iOS-root-path'. Typically this is defined in the previous step of this action");
    }

    url = "shareddocuments://" + rootPath + "/" + fileName
    app.openURL(url, false)
}

Notice in my action you need the template tags set:

1 Like