Skip to content

Instantly share code, notes, and snippets.

@dartov
Created January 22, 2012 18:05
Show Gist options
  • Save dartov/1657926 to your computer and use it in GitHub Desktop.
Save dartov/1657926 to your computer and use it in GitHub Desktop.
Shell script to run native mac apps from command line
#!/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