Created
January 22, 2012 18:05
-
-
Save dartov/1657926 to your computer and use it in GitHub Desktop.
Shell script to run native mac apps from command line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
set -e | |
if [[ $# -ne 1 ]]; then | |
echo 'Sorry, need only one parameter'; exit 1; | |
fi | |
FILENAME="$1" | |
if [[ ! -e "${FILENAME}" ]]; then | |
echo 'Sorry, looking for an existing file or directory'; exit 1; | |
fi | |
full_app=$( | |
osascript 2>/dev/null <<EOF | |
set afile to "${FILENAME:a}" | |
tell application "System Events" | |
get default application of disk item afile | |
end tell | |
EOF | |
) | |
the_app=$(echo "$full_app" | sed 's/.*:\([^:]*\):$/\1/') | |
open -a "${the_app}" "${FILENAME:a}"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment