knurling / ServiceStation

Service Station
39 stars 1 forks source link

Need a file path for scripts to use. #25

Closed rob-dodson closed 4 years ago

rob-dodson commented 4 years ago

The SELECTED_ITEM_URLS are not really urls as far as I can tell. They contain spaces and colons, etc and can not be used to open a file. I am not sure how they are supposed to be used. I have to process your URL into a real file path. It would be nice if you can pass a real complete file path to the selected items.

Thanks, Rob

pkamb commented 4 years ago

Hi Rob, which kind of script are you using? Can you give an example of the URL Service Station is providing and the version after your processing? Thanks!

rob-dodson commented 4 years ago

ServiceStation sends into my script: arg1: Macintosh arg2: HD:Users:rob:Desktop:BikeBlog.json

To open the file I have to translate that to:

/Users/rob/Desktop/BikeBlog.json

ServiceStation calls an Applescript to launch iTerm2 with this python script as iTerm2's start up command:

!/usr/bin/python3

# import sys import subprocess arg = sys.argv[2] arg = arg[arg.index(':')+1:] arg = "/" + arg.replace(":","/") subprocess.run(["/usr/bin/vi", arg])

pkamb commented 4 years ago

Service Station passes the AppleScript the FIFinderSyncController data like so:

<NSAppleEventDescriptor: [
    "file:///Users/user/Desktop/", // targetedURL
    ["file:///Users/user/Desktop/file.txt"], // selectedItemURLs
    0 // menuKind
]>

But when run by the sample AppleScript, that produces the same colon-delimited output that you're seeing:

Screen Shot 2020-04-30 at 3 44 38 PM

This is because AppleScript uses the Classic Mac OS-style "HFS" paths, while your script is expecting UNIX POSIX paths.

There are examples in the first link of easily converting between the two path styles.

You could also possibly call your shell script directly rather than wrapping it in AppleScript...?

Do either of those options seem like they will work?

rob-dodson commented 4 years ago

Thanks for the response! I did not know about the classic HFS paths. So now I use the Applescript code: set thisPOSIXPath to (the POSIX path of oldPath) to covert the path instead of doing it in my python code. Python is the best way to run a script in iTerm2 so I use it to start vim in the terminal window.

I might suggest this be better documented in your sample scripts? Also, pass in the Posix path too as it is more commonly used these days.

Thanks again for your help and good luck with the app.

rob-dodson commented 4 years ago

Yes, I can use a shellscript directly. At first I thought it was getting the same HFS path but I now see it is getting a posix path.

pkamb commented 4 years ago

Also, pass in the Posix path too as it is more commonly used these days.

I am passing the POSIX path... AppleScript translates it to HFS. I think all AppleScript files use HFS by default and the script developer is responsible for using the utility functions to translate to POSIX if needed.

Or at least that's how I understand it.

rob-dodson commented 4 years ago

Ah ok, I get it, thanks. On May 1, 2020, 7:50 PM -0700, Peter Kamb notifications@github.com, wrote:

Also, pass in the Posix path too as it is more commonly used these days. I am passing the POSIX path... AppleScript translates it to HFS. I think all AppleScript files use HFS by default and the script developer is responsible for using the utility functions to translate to POSIX if needed. Or at least that's how I understand it. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.