No internet connection
  1. Home
  2. How to

how to have the user select a file in the finder and pass it to SF

By Davide Favargiotti @dieffe
    2018-08-07 17:18:09.634Z

    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

    Solved in post #5, click to view
    • 8 replies
    1. D
      Davide Favargiotti @dieffe
        2018-08-07 17:35:07.122Z

        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)

        1. 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;
          
          1. DDavide Favargiotti @dieffe
              2018-08-20 19:12:10.959Z

              Thanks @chrscheuer, but how to get the full path+name+extension or just the name+extension that I can combine with the path?

              1. @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);
                
                Reply1 LikeSolution
                1. 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.

                  1. DDavide Favargiotti @dieffe
                      2018-08-20 19:36:26.273Z

                      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.

                      1. @dieffe, very interesting. Looking forward to seeing that!