Skip to content

Instantly share code, notes, and snippets.

@LazyRen
Created August 23, 2018 20:56
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/4e3a89ac10dcac82ebaaadade445c659 to your computer and use it in GitHub Desktop.
Save LazyRen/4e3a89ac10dcac82ebaaadade445c659 to your computer and use it in GitHub Desktop.
mac sublime-text python 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
tell application "System Events"
if not (exists (processes where name is "Terminal")) then
tell application "Terminal"
activate
do script ("cd " & quoted form of filePath & "; clear") in first window
delay 0.1
do script ("python3 " & quoted form of myfile) 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 ("python3 " & quoted form of myfile) in selected tab of the front 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