open file in folder with command line program

I have a file, which is in native format for a given program [1] I have installed. This program I can start from Terminal.app and within the program I can open the file. The question is if I can have associated with this specific filetype this program and when I double click on a file of this type I can have a Terminal.app opened with my program running inside opening the file for me.

Btw, on a regular Linux/Unix I would just associate this filetype with the path to my program. On Mac I can associate only with .app.. Is there other way?

[1] http://root.cern.ch/drupal/

MacBook Pro, Mac OS X (10.6.4)

Posted on Oct 18, 2010 6:33 AM

Reply
7 replies

Oct 19, 2010 9:59 AM in response to IvanGlushkov

I do not fully understand your question.

You need to make your program into an application. I have not programmed on Mac OS so I to not know the details. You could hack some existing app. I do know that the plist file for an app points to the starting program.

--------

Another work around would be to write an apple script file to call your program.

This applescript invokes a unix program.

(*
Run in the Script Editor.
Click on the Event Log tab to see the output from the log statement
Click on Run


For running shell commands see:
http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html

*)

on run
-- Write a message into the event log.
log " --- Starting on " & ((current date) as string) & " --- "


-- ask the user for the folder name.
-- quoted form of (POSIX path of (choose folder))

set theFolder to "/Applications/Utilities/Disk Utility.app"
set theFolder to quoted form of theFolder
log "quoted form is " & theFolder

-- running two Unix commands. Separate with a semicolon
set fromUnix to do shell script "cd " & theFolder & "; ls -ld ."

log fromUnix
display dialog fromUnix giving up after 30
end run



This applescript program received a file dropped on it.

There is a lot of extra stuff but look at on open dropped_items This line gets a list of files dropped on the applescript. Your have to change the name format.


on open dropped_items
-- Remember you need to turn on enable assistive devices
-- this lets applications software to access screen elements
-- blue apple > system perferences > universal access > enable assistive devices

-- Write a message into the event log.
log " --- Starting on " & ((current date) as string) & " --- "
-- set see to alias "Macintosh-HD:Users:mac:Desktop:app.html"
-- set dropped_items to {see}

set the_app to "Safari"


repeat with dropped_item_ref in dropped_items
--set UrlBase to "xzzx FILE://" & POSIX path of dropped_item_ref
--display dialog UrlBase

-- Activate
activate application the_app

-- Open the URL
tell application the_app
open dropped_item_ref
-- print dropped_item_ref
tell application "System Events"
tell process the_app
delay 3
-- click menu item "Print..." of menu "File" of menu bar 1
keystroke "p" using command down
delay 1
keystroke return
delay 10
keystroke "w" using command down

end tell
end tell

--quit
end tell

end repeat
end open

Oct 19, 2010 5:15 PM in response to IvanGlushkov

This should work.

Applications -> Automator -> Custom

Use: "Run Shell Script"

Replace the 'cat' with:

PROGRAM=/path/to/your/unix/command/line/program # YOU CUSTOMIZE THIS LINE!!!
SCRIPT=/tmp/Drag-N-Drop-Terminal-Starter.$$
( printf "#!/bin/bash "
printf "${PROGRAM} %q " "$@"
) >"${SCRIPT}"
/bin/chmod +x "${SCRIPT}"
/usr/bin/open -a Terminal "${SCRIPT}"
/bin/rm "${SCRIPT}"

VERY IMPORTANT: Change the "Run Shell Script" -> Pass input to "as arguments". This is a button in the upper right corner of the "Run Shell Script" Automator box. If you forget this step, the "Run Shell Script" will not see your file name.

Automator -> File -> Save As... -> Application

You now have an application with .app that you can associate with your file, or all files with that .type

Select a file you want your /path/to/your/unix/command/line/program to process when you double-click on the file.

Finder -> File -> Get Info

Change "Open with:" -> Other... Find your saved Automator .app and choose it as the application you want to open the file with.

Optionally click "Change All..." but ONLY if you want every file with the same .type to be processed by your program.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

open file in folder with command line program

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.