How the FSShortcut code works

I am trying to understand how this code from FSShortcuts works.

//Create a bookmark for a file object passed directly from the Shortcuts app

var fm = FileManager.iCloud()

// Get the file parameter from Shortcuts
var name = args.shortcutParameter
// Get the file type parameter from Shortcuts
var bookmarkType = args.plainTexts[0]

var file = fm.bookmarkedPath(name)

// Output the file path as a dictionary to force plain text
Script.setShortcutOutput({"path":file, "name":name, "type":bookmarkType})

Where does the bookmark type get it’s value?

So far I have created a Bookmark in Scriptable called Batman which is in the directory iCloud/Batman.

I then use the following shortcut:

The output gives the path and name but not the bookmark type?

SO I now have the path for the folder, I just don’t know how to use it?

Basically I am trying to work out how the code works so I can search in that folder for other folders with that directory with the name ABCD

It should be getting it from the item passed in from Shortcuts as per the comments. If you look at the Shortcut rather than the JavaScript, you’ll see file bookmark creation passes in one file argument, but folder creation passes in a dictionary. Try bookmarking a folder and see if that gets you a type.


That helped so much and was a big help.

I’ve now managed to get the url and it opens the folder but I now need to list the folders.

I have removed the part where it opens the folder in the Files app and added a filter but it doesn’t work, please see link.

What am I doing wrong? Or does this need to be done it scriptable?

I’ve been looking for how to list at folders using JavaScript and I can’t get anything to work.

If I were using Scriptable for file bookmarks, and wanting more file/folder information, I’d try and process it in Scriptable. If I wanted to focus on working with it in Shortcuts, I’d use Toolbox Pro’s bookmarks functionality.

Focusing on Scriptable, if I add a folder bookmark for a folder like this, containing files and folders (which contain further files and/or sub-folders themselves)…

… then use listContents() and isDirectory() to get the content of the folder and the “directory-ness” of each thing in the folder…

let fmCloud = FileManager.iCloud()
let strPath = fmCloud.bookmarkedPath("Drafts")
fmCloud.listContents(strPath).forEach( function(p_strPath)
  console.log(fmCloud.isDirectory(p_strPath) + " | " + p_strPath)

… I’d expect to be able to identify both the element of content, and if it is a folder or a file …

… the results unfortunately don’t match my initial expectations :confused:

If anyone has any insight into the isDirectory() results, that could close the gap perhaps?

Thanks for that.

I was waiting to reply in case someone else came into the mix with an option but it feels like we’re the only ones here using scriptable.

OK, found the issue, you were checking by the name and not the path.

I’ve updated the code and it now works.

let fmCloud = FileManager.iCloud()
let strPath = fmCloud.bookmarkedPath(“Batman”)
fmCloud.listContents(strPath).forEach( function(p_strPath)
console.log(fmCloud.isDirectory(strPath + “/” + p_strPath) + " | " + p_strPath)

1 Like

So…would it be possible to programmatically create a set of arguments on a Mac (with say an Alfred file action) and then pass them to Scriptable to create the bookmarks?

How would you pass them to Scriptable? Scriptable is an iPhone/iPad app.

Unless Scriptable gets updated to install on a Mac it would make it a lot harder. I wouldn’t say impossible. As Far as I’m aware Alfred is a MacOS app, Shortcuts will be included in the next MacOS release but you’re still limited without Scriptable.

Which macOS version have Apple announced that for?

I thought I read that Shortcuts were coming in MacOS Big Sur? I’m doubting myself now but I’m pretty sure they’re coming.

I’ve personally not seen that and I definitely heard pundits discussing the contrary position during WWDC. I’ve done a few quick web searches and nothing definitive has shown up. But absence doesn’t constitute proof - it could well be I’ve missed the news somehow. :man_shrugging:t2:

I’ve been wondering how Shortcuts might play on an Apple Silicon-based Mac, but it would need to be part of Big Sur as it is an OS-level application since transitioning from Workflow. But I’ve not seen anything confirm that it would be an option.

Drop them in a file somewhere then manually run an import script on an ios device.

Okay. I guess sometimes it may be easier to produce a list on a Mac if you already have something in place, but I would imagine you could produce the same on the mobile device anyway.

Just remember that if you do take this approach that you also need to change the initial part of the paths produced as that differs between macOS and i*OS. On Mac the library lives in your home directory whereas on the iPhone and iPad it lives off the root in /private/var/mobile.