Is it possible to have a window in SF asking the user to get a file in the finder (to pass the pathname of that file to SF)?
Thanks
- DDavide Favargiotti @dieffe
I can imagine it would work also if I select a file in the finder and then launch the SF script (to get the full pathname of the selected file)
Christian Scheuer @chrscheuer2018-08-08 00:02:33.608Z
You can get the path of the currently selected item in the top level finder window like this:
var myFilePath = sf.appleScript.finder.firstWindow.targetPath;
- DDavide Favargiotti @dieffe
Thanks @chrscheuer, but how to get the full path+name+extension or just the name+extension that I can combine with the path?
Christian Scheuer @chrscheuer2018-08-20 19:32:39.613Z
@dieffe, sorry the first solution I posed would give you the full path of the folder in the front most window, not the path to any file selected in that window.
This script will get you first the first selected file's full path, and then afterwards we extract the different parts composing the path (directory, filename with extension, filename without extension, extension)
var fullPath = decodeURIComponent(sf.appleScript.finder.selection.getItem(0).asItem.path); var directory = fullPath.split('/').slice(0, -1).join('/'); var filename = fullPath.split('/').slice(-1)[0]; var filenameWithoutExtension = filename.split('.').slice(0, -1).join('.'); var extension = filename.split('.').slice(-1)[0]; log(fullPath); log(directory); log(filename); log(filenameWithoutExtension); log(extension);
Christian Scheuer @chrscheuer2018-08-20 19:33:58.856Z
Note that we are building new actions in SF where you can open an "file open dialog" or a "directory open dialog" or a "file save dialog", like any other software where you open/save files. The feature is mostly implemented but it still has some bugs.
- DDavide Favargiotti @dieffe
Very nice, thank you! I've been away on holiday with my family this past week, but now I'm back in front of my computer :) And I'm trying to finish that script that can read preferences from a file. Hope to finish it tonight and post it later.
Christian Scheuer @chrscheuer2018-08-20 19:36:57.701Z
@dieffe, very interesting. Looking forward to seeing that!
- DDavide Favargiotti @dieffe