A little more context:
Successfully opening anything via shell.openPath / openExternal requires manifest V5, and setting proper permissions for launching stuff.
Note that if you want to open a FOLDER, and not a file, you have to include "" in the "extensions":[] array. Here is what I use in my v5 manifest in order to get shell.openPath to open a folder:
hi @Zob@grebesoft_ben could you explain a little bit about getting shell.openPath to open a folder? On windows would it be the same as the file explorer window? Man this might be what I need to access any folder in any directory.
Yes, using shell.openPath actually opens a file Explorer window on Windows if you pass in the path to a folder. I use it so a user can see the folder containing the content generated by my plugin. doing this is of no use to my plugin, because I get no variable with which to manipulate the folder.
If you are interested in having programmatic control of any folder on the harddrive, such as being able to read and save files via javascript, you will need to use require('uxp').storage.localFileSystem .
ask the user for the root drive (e.g. J:// ) by using localFileSystem.getFolder()
Note: You will need to explicitly tell them to select the root drive using a pop up before calling getFolder()
The folder they picked returns to you as a folderEntry object. Ensure its the root drive, and then use localFileSystem.createPersistentToken(folderEntry) to create a token, which allows you to get this file entry in the future without asking the user.
Save the token to your plugin’s localStorage. In the future, when a user opens photoshop again, your code should check localStorage for the token, thus avoiding steps 1 and 2. Instead, you just call localFileSystem.getEntryForPersistentToken(token)
In order to access the subfolders, you need to write a function that calls getEntries() on your current folderEntry, find the right subfolder in that array, and then creates a new folderEntry or fileEntry from that, and then calls getEntries() again. You repeat this until you reach your desired folder or file. You could probably write a recursive function for this.
If someone knows a less convoluted way to access an entire drive, please share. This is the only method I found.
@Zob This is fantastic, it worked almost perfect! Thanks,
I also need this feature so that the user gets the directory with content generated after the finished event and can select the files and drag them to another program.
The problem is how to avoid the “Request For Permission” window, this is not cool when working with different directories. Thanks for pointing me to the right path.
Agreed, it’s a hassle for the user to keep approving these with workflows which might organize the user’s work into different folders.
Opening a folder doesn’t create a security risk, writing data does. If there is a concern that a plugin might entice a user to click on a bad file it creates, not showing the folder doesn’t eliminate that risk.
@pkrishna@kerrishotts Is there a way to avoid granting permissions for each unique folder a plugin wishes to show? If not possible now, perhaps it could be removed or revised to use a single approval for the plugin to show any folder it is allowed to read/write?