#!/bin/zsh -f # Popup dialog box to get the arguments for the shell-script # Cocoa-Dialog does the same thing but I can't get it to work function GetArgs { osascript << eof-1 tell app "Finder" activate set prompt to "Enter a list of arguments or hit OK to leave blank: " set dialogResult to display dialog prompt default answer "" end tell eof-1 } if [[ ! -x "$TM_FILEPATH" ]]; then res=$(iconv </dev/null tell app "TextMate" to return button returned of ¬ (display dialog "To run “${TM_FILENAME}” as a shell script it needs to be executable.\n\nWould you like to make it executable?" ¬ buttons {"Cancel", "Make Executable"} ¬ with icon 1 default button 2) APPLESCRIPT) if [[ "$res" != "Make Executable" ]]; then echo ''; abort; exit; fi chmod a+x "$TM_FILEPATH" fi arg_array=( $( GetArgs | cut -f 2 -d ":" | cut -f 1 -d "," )) ThePath=( "$TM_DIRECTORY" ) BaseName=( $(basename "$TM_FILEPATH" ) ) source "$TM_SUPPORT_PATH/lib/webpreview.sh" html_header "Running ‘${TM_FILENAME} ${arg_array}’ in $TM_DIRECTORY" print "Output from command sequence \"$BaseName $arg_array\"" # Format the command standard output to appear within a box with proper line breaks echo "

"

# cd to the directory, run the command, report on its success
cd "$ThePath"
$BaseName $arg_array 
exitstatus=$?

echo "

" # Tell us if it worked: print "Exiting with status $exitstatus" html_footer