Skip to content

Instantly share code, notes, and snippets.

@LazyRen
Created August 23, 2018 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LazyRen/da3cac957c5e203d99605b0815ca5ff8 to your computer and use it in GitHub Desktop.
Save LazyRen/da3cac957c5e203d99605b0815ca5ff8 to your computer and use it in GitHub Desktop.
mac sublime-text c build&execute shell script
#!/bin/sh
osascript -e '
on run parameters
set TID to text item delimiters
set text item delimiters to " "
set myfile to parameters as text
set text item delimiters to TID
tell application "Finder"
set fileName to name of (POSIX file myfile as alias)
set filePath to do shell script ("dirname " & quoted form of myfile)
end tell
set fileBaseName to text 1 thru ((offset of "." in fileName) - 1) of fileName
tell application "System Events"
if not (exists (processes where name is "Terminal")) then
tell application "Terminal"
activate
delay 0.1
do script ("cd " & quoted form of filePath & "; clear") in first window
delay 0.1
do script ("./" & fileBaseName & ".out") in first window
end tell
else
tell application "Terminal"
activate
delay 0.1
tell application "System Events" to tell process "Terminal.app" to keystroke "n" using command down
delay 0.1
do script ("cd " & quoted form of filePath & "; clear") in selected tab of the front window
delay 0.1
do script ("./" & fileBaseName & ".out") in first window
end tell
end if
end tell
end run
' $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment