Hello,
I'm currently trying to make an AppleScript which should recognize the selected file in Finder and do the relative command in Terminal.
Everything was going fine since I reached the part where it should define the language of the selected file: it just doesn't check the ifs. I checked if it writes fileExtension correctly (via return) and it does.
Thanks
--> 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 "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 "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