Shell script: whence the "/" prepended to my shell command argument?

Here are the last two action condensations before the Executed Shell Script action below:
Prepend Text """ to Variable "Local_toOpen"
Append Variable "Local_toOpen" with Text """
i.e., surround the contents of the variable with double-quote marks.

The last action in the macro is Execute Shell Script:
open $KMVAR_Local_toOpen

The result: Execute a Shell Script failed with script error: The file /“/Applications/Thunderbird.app“ does not exist.

Where does that first slash come from? I put it to this honorable Court that since the last thing I did was prepend and append double-quotes, it did not come from me.

Open App from Hard-coded List .kmmacros (8.8 KB)

Since you haven't shown us your macro, it's hard to be sure if the macro contains the typo that I see in your question, but your question shows the wrong kind of double quotes. That's either a typo in your message or a typo in your macro.

So I just need to ask if you have smart quotes disabled in System Settings, in the following:

The honourable court asks you to call your next witness.

What typos? All the double-quotes see are the straight-up-and-down kind.

How do I show the macro? Peter's intro to the Library mentions an editor "share" button, but I'm not seeing one.

I was talking about the quotes in your error message:

image

If that was your error message, then your quotes may be the cause of your problem, which is why I was asking you to check something in System Settings.

I don't know anything about that, but I know there is a Share menu item in the Keyboard Maestro Editor under the File menu. It takes time to master, but there's where you find it.

Put a Display Text in Window action before the shell script, and display the variable. What do you see there?

-rob.

I saw curly quotes. Fixed that. But still...
The file /"/Applications/Thunderbird.app" does not exist.

Put the $KMVAR in double quotes—any change?

-rob.

I fixed the curly quotes. Dunno why the other double-quotes in my OP are straight. I like curly quotes for human consumption, when I'm not writing code. I hope turning them off in System Settings won't ruin my life.

Meanwhile, the OP's title question still stands.

No change; same error message.

Since you haven't shown us your macro, and since you seem to be implying that you have turned off the smart quotes, then the next step is to delete your action and recreate it. Hopefully then the correct quotes will be passed to the shell.

Or you can try to learn how to upload your macro so we can see it and troubleshoot faster.

I learned; see OP.

P.S. Here is the error message; notice the quotes:
The file /"/Applications/Thunderbird.app" does not exist.

1 Like

Thanks. It takes me time to read someone else's macro. I'm still studying it. I see a small error, a double space before Excel. Not the main issue here though.

Don't do it this way -- put the quotes in the shell script action instead, so the script becomes:

open "$KMVAR_Local_toOpen"

The way you're doing it you are passing the path "/Applications/Safari.app" with the double-quotes as part of the actual path -- you're saying "start at the " directory". Because it isn't a valid absolute path (doesn't start with /), open will try to evaluate it in the context of the current working directory -- which for an "Execute a Shell Script" action is the root directory /.

That's where the extra / is coming from -- the error message is saying "starting at / I can't find the file "/Applications/Safari.app" because there's no directory named " in the root directory".

Also -- do you have a need for the shell script? You're spending resources unnecessarily and slowing things down -- it takes CPU cycles and time to instantiate then delete the shell -- and will cause you more problems than a simple:

1 Like

Well, even if you stop using variables and just say: (using any app, I'm trying the app "Home")

image

It still gives you the error message. So the problem isn't with your variables, it's with your command.

Even if you don't use KM, and type that command directly into a Terminal window, you still get that error:

myname@MyNames-iMac ~ % open "/Applications/Home.app"
The file /Applications/Home.app does not exist.

So I guess the questions is now no longer about KM, but about how to use the open command. I'll let you look into that first, as the KM issue is no longer an issue.

By the way, you should not put Finder in that list, as it's not in the /Applications folder, at least not on my Mac.

That fixes the OP title question!

1 Like

The macro works with Thunderbird, but I get the "does not exist" error with Preview, both from the macro and manually in the terminal. Maybe the error occurs with Apple apps?

Right, I have to special-case Finder and maybe some others.

That's a theory. But until you can get the open command to work with Apple apps, your script won't work. I can't get it to work with Apple apps either.

But did you try Nige's suggestion to use the open action instead of the shell? What results did you get?

Apple's stock apps live here:

/System/Applications

Everything else is in /Applications. Finder does some magic to make it look like they're all in /Applications.

-rob.

2 Likes

"Open ... with Finder" works, as long as I give it the right path.