2

I have a program which I want to share with another Mac user who will not use the command line. This is essentially the same problem faced here:

Easy way to launch Python scripts with the mouse in OS-X

The simplest solution proposed in answer to the above question is to create a clickable application with Automator that runs a shell script that opens the program. However, this appears to require locating the program with an absolute path, which relies on my knowing where my fellow Mac user will install it on his or her hard drive. What is the simplest way of automating the launch of a program that is in the same folder as the Automator application, when we don't know the absolute path of that folder?

Community
  • 1
  • 1
Westcroft_to_Apse
  • 1,503
  • 4
  • 20
  • 29
  • How will the user obtain your program? Is it a standalone script file or other executable? Does it have to be installed? Will you need the user to provide arguments? – Ken Thomases Jan 11 '14 at 03:21
  • It's a standalone script file that takes no arguments; I could email it straight to the user, but then he/she would need to open Terminal to run it, so I'd rather zip it up in a folder together with an Automator application that contains a shell script that will run it when clicked. However, this appears to rely on my knowing the absolute path for the folder. I believe the problem really is as simple as described above: I could do all this if only I knew how to use a relative path in an Automator shell script. – Westcroft_to_Apse Jan 11 '14 at 08:42

1 Answers1

2

In that other question you refer to, I suggested Platypus. I think that's better than Automator for your use case. Is there a reason you don't use that?

If you want to use Automator, you could paste the script into it rather than having it run a script that runs your standalone script.

Depending on quite how allergic your user is to the Terminal, you could simply supply the script with a .command file extension. In that case, when they double click it, it will open and run in Terminal automatically. They won't have to enter any Terminal command manually, which may be what they want to avoid, but they will have to see Terminal.

Community
  • 1
  • 1
Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • Thanks very much for the useful practical solutions to my actual problem, Ken! I've voted up your answer and will try all of those ideas: the `.command` extension is a particularly interesting option. However, I am curious to understand how to use Automator, so I am still holding out for someone to answer the question itself (as opposed to solving the real-world problem that led me to ask the question) by explaining how to use relative paths within Automator. (I have heard that this is possible using AppleScript, but I haven't seen a clear explanation of how to do it.) – Westcroft_to_Apse Jan 11 '14 at 10:03
  • I did some experimentation with Automator. None of the built-in variables contain the app path. I built an application around the Run Shell Script action with the script being `echo "$@" ; env`. I did not find anything valuable. The working directory was not related to the location of the saved app bundle. No environment variable had its path, either. It doesn't seem possible, although I may be wrong. – Ken Thomases Jan 11 '14 at 10:28
  • Thanks very much for the investigative work, Ken! It sounds as if the answer to the question as asked may simply be 'It can't be done.' – Westcroft_to_Apse Jan 11 '14 at 13:38