my goal is to use Automator to open an application with arguments
open ./MyApp.app -arguments
via running a shareable Buddy.app with Myapp.app (the Automator/workflow). both apps should be shareable together with anyone so they run straight off.
the simplest way to do so, seems to be to run the Buddy.app from within the same folder as MyApp.app.
then i can move the Buddy.app with MyApp.app anywhere, and they will still work together
to set up the relative file locations in bash script,
open "$(pwd)"/myapp.app -arguments
only problem is that Automator uses the home directory instead of the application directory.
ie pwd is the home directory, and not the actual file location.
in Automator the output from
echo $(pwd)
is my home directory, /Users/User
so the question is, how to get Automator (Buddy.app) to detect the current folder location and run MyApp.app ?
Best Answer
Have your workflow figure out its own path (more robust)
This works as long as your Automator workflow lives in the same directory as
MyApp.app
; you can create copies of either the workflow or the app at your discretion and reuse those copies wherever you want; nothing needs to be unique.Steps
These are the steps to automate launching
MyApp.app
:Open the workflow in Automator.
Add a Run AppleScript action. Remove all the boilerplate code inside and replace it with the following lines:
Save the Automator workflow in the same folder as
MyApp.app
.Run the Automator workflow; it should launch
MyApp.app
.Explanation
This means “Watch out, I’m going to split a string soon; and I want you to use the
:
character as the split boundaries.”This instructs the workflow to figure out the path to itself; path components are delimited by a colon (
:
), which is a remnant of Classic Mac OS.This cuts off the last part of the path, and appends
MyApp.app
to the path.This pieces the path back together (again with
:
as a delimiter).Lastly, this final line causes
MyApp.app
to launch.