(* Demonstration macOS/OSX app in AppleScript and Perl *) (* Posted to perlmonks.org by Anonymous Monk 6/14/2018 *) (* Node: How to write apps for macOS/OSX in Perl! Part 2 *) set TITLE to "Perl Version Tool" set PROMPT to "Make a selection" set _1 to "Perl version, patchlevel and license" set _2 to "Perl configuration summary" set _3 to "Perl command line help" set _4 to "Visit Perlmonks.org!" repeat set what to choose from list {_1, _2, _3, _4} with title TITLE with prompt PROMPT OK button name {"View"} cancel button name {"Exit"} default items _1 set what to what as string if what is _1 then set CMD to "perl -v" # ONE LINERS OR PROGRAMS OF ANY SIZE! else if what is _2 then set CMD to "perl -V" else if what is _3 then set CMD to "perl -h" else if what is _4 then display notification "Opening The Monastery Gates!" set CMD to "open https://perlmonks.org" else if what is "false" then return # EXIT end if if what is _2 then # SEND PERL CODE TO TERMINAL AND EXECUTE doShell(CMD) else if what is _3 then # CAPTURE PERL STDOUT set CMD to do shell script CMD # SEND PERL STDOUT TO TEXTEDIT textEdit(CMD) else # CAPTURE PERL STDOUT set RES to do shell script CMD # MAKE DIALOG WIDE set SPC to " " # PRINT PERL STDOUT TO APPLESCRIPT ALERT display alert TITLE message RES buttons {SPC & "Cool" & SPC} default button 1 end if end repeat # APPLESCRIPT SUBS: on doShell(CMD) try tell application "Terminal" activate tell application "System Events" to keystroke "n" using {command down} end tell tell application "System Events" tell application process "Terminal" set frontmost to true keystroke CMD keystroke return end tell end tell on error oops display alert oops as critical end try end doShell on textEdit(CMD) try tell application "TextEdit" activate tell application "System Events" to keystroke "n" using {command down} end tell tell application "System Events" tell application process "TextEdit" set frontmost to true keystroke CMD end tell end tell on error oops display alert oops as critical end try end textEdit