Skip to content

Instantly share code, notes, and snippets.

Created June 13, 2010 13:53
Show Gist options
  • Save anonymous/436674 to your computer and use it in GitHub Desktop.
Save anonymous/436674 to your computer and use it in GitHub Desktop.
------------------------------------------------------------
-- The Mad Scripter
-- by Giovanni Cattani
-- http://
-- last-modified: 11 June 2010
------------------------------------------------------------
--> Useful variables
set fileCheck to false
set languageCheck to false
set selectionCheck to false
set fileExtension to ""
set myCommand to ""
--> Get selected file
tell application "Finder"
if selection is {} then
tell application "Terminal"
activate
end tell
else
set finderSelection to selection as alias list
set selectionCheck to true
end if
end tell
--> Get file POSIX path
if selectionCheck is true then
set filePath to quoted form of POSIX path of finderSelection
end if
--> Get file extensions
if filePath contains "." then
set fileCheck to true
set fileExtension to text ((offset of "." in filePath) + 1) thru -1 of filePath
end if
--> Check language
-- No Extension
if fileCheck is false then
display dialog "The Mad Scripter warning:
the file you selected has no extension" buttons ("Ok") default button 1
-- Text
else if fileExtension is "txt" then
set myCommand to "open"
set languageCheck to true
-- Perl
else if fileExtension = "pl" then
set myCommand to "perl"
set languageCheck to true
-- Ruby
else if fileExtension is "rb" then
set myCommand to "ruby"
set languageCheck to true
-- Python
else if fileExtension is "py" then
set myCommand to "python"
set languageCheck to true
-- AppleScript
else if fileExtension is "scpt" then
set myCommand to "osascript"
set languageCheck to true
else
display dialog "The Mad Scripter warning:
the extension is not supported" buttons ("Ok") default button 1
end if
--> Terminal time!
if fileCheck is true and languageCheck is true then
do shell script "" & myCommand & " " & filePath
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment