Skip to content

Instantly share code, notes, and snippets.

@windwiny
Created August 7, 2016 08:35
Show Gist options
  • Save windwiny/b7b82db26842125e837de9f5d11fc0ec to your computer and use it in GitHub Desktop.
Save windwiny/b7b82db26842125e837de9f5d11fc0ec to your computer and use it in GitHub Desktop.
apple script run command on finder in current path
with timeout of 3600 seconds
tell application "Finder"
set sel to (get selection)
if not sel = {} then --selected file/dir
repeat with f in sel
set _cwd to POSIX path of (folder of f as alias)
exit repeat --first item path
end repeat
else --not select
set _cwd to POSIX path of ((folder of (front window)) as alias)
end if
set diglog1 to display dialog "Hello, welcome to this App!
Please input command ..." & return & "" default answer "" buttons {"Cancel", "Run…"} with icon stop with title "Run command with..." default button 2 with answer
set cmd to text returned of diglog1
set btn to button returned of diglog1
if btn is "Cancel" then
--display notification "cancel"
else
if cmd is "" then
--display notification "cmd is empty"
else
--display notification "run cmd: " & cmd
set cmd2 to "cd '" & _cwd & "'; " & cmd
set result2 to do shell script cmd2
set cpdlg to display dialog "cd '" & _cwd & "'
Run command: " & cmd & "
Result:
" & result2 buttons {"Copy Result", "OK"} default button 1
if button returned of cpdlg is "Copy Result" then
do shell script "echo " & quoted form of result2 & " | pbcopy"
end if
end if
end if
end tell
end timeout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment