I would start with a tool like Platypus to make your script have all the accoutrements of an App and test to see that things work as expected.
Automator also has a nice GUI for deciding how to handle arguments to a script - and we have several questions here that explore how to pass arguments into and out of an Automator action / applet.
Without more details on how your daemon is designed and how you launch it, I can only pick away at some of the elements to your solution, but since anyone can edit this answer to provide more details (or answer a stand-alone answer) - perhaps this can get the ball rolling to get you a solution.
AppleScript is your friend.
In the AppleScript Editor, create a new script, with the following source code :
(* This script is destined to be saved as an application droplet. It will process the items dropped onto it. *)
-- This routine processes the dropped item(s)
on open theDroppedItems
repeat with i from 1 to the count of theDroppedItems
set aDroppedItem to item i of theDroppedItems
processItem(aDroppedItem)
end repeat
end open
-- This routine processes an item
on processItem(anItemToProcess)
set pathUnix to POSIX path of anItemToProcess
set pathUnixQuoted to quoted form of pathUnix
-- Here you make your shell command !
set commandToRun to "cat " & pathUnixQuoted
do shell script commandToRun
end processItem
For the shell command, adapt the commandToRun
to your desires.
Save the script. In the Save dialog :
- Name the script OpenItems.
- Place the script somewhere you like ; for example, you can place the script in /Applications.
- Choose the format : Application.
- Leave the two check boxes unticked.
In the source code, look at the construction on open theDroppedItems
. This sort of AppleScript is called a droplet. Look at the icon of the application OpenItems you have saved. The big arrow on it shows that it is a droplet. It means that the application accepts item(s) dropped onto it.
Now, drag-and-drop the file you want onto the application OpenItems. This will launch the command with your file.
The next step is associating the file(s) with the droplet. Select the file you want, and press Apple I ( ⌘ I ) to get info. In Open with, choose the application OpenItems. This will associate the file with the droplet. So, when you double-click the file, the file will be opened with the droplet OpenItems, and the shell command for the file will run. If you want this for all files of the same type, click the button Change all…
I have tested this solution on Mavericks. It works.
Best Answer
You can use
pgrep
instead ofpidof
on OS X. Using your example from earlier, the following should work:That said, a child started after the parent has had their priority changed should inherit the parent's priority.