Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: How to create GUI for a perl script on MAC?/Apple Script and Perl?

by karlgoethebier (Curate)
on Jan 18, 2013 at 14:42 UTC ( #1014068=note: print w/ replies, xml ) Need Help??


in reply to How to create GUI for a perl script on MAC?/Apple Script and Perl?

Like this:

AppleScript

set theWindowTitle to "PerlMonks" set theOption to text returned of (display dialog "Enter a Source fold +er:" & return default answer "" with title theWindowTitle) set thePerlScript to quoted form of (POSIX path of ((choose file with +prompt "Select a script:") as Unicode text)) set theResult to do shell script thePerlScript & " -S " & theOption display dialog "Result: " & theResult with title theWindowTitle

Perl

#!/usr/bin/perl use strict; use warnings; use Getopt::Long; Getopt::Long::Configure("ignore_case"); my %options; GetOptions(\%options, "SourceFolder=s"); print $options{SourceFolder};

Update: see also Getopt::Long

Regards, Karl

«The Crux of the Biscuit is the Apostrophe»


Comment on Re: How to create GUI for a perl script on MAC?/Apple Script and Perl?
Select or Download Code
Re^2: How to create GUI for a perl script on MAC?/Apple Script and Perl?
by hary536 (Novice) on Jan 21, 2013 at 02:19 UTC
    Thanks Karl, I didn't notice your post until later today. I spent quite a bit of time on friday and saturday researching for my problem solution. Came across this Apple tech note, which helped some. http://developer.apple.com/library/mac/#technotes/tn2065/_index.html Then I wrote following code to see if it will work:
    set cfgfolder to choose folder with prompt "Choose the Configs folder: +" default location alias "MacHD:Folder1:Folder2:Configs:" set cfgposix to POSIX path of cfgfolder set sourcefolder to choose folder with prompt "Choose the source fold +er:" default location alias "MacHD:Folder3:Folder4" set sourceposix to POSIX path of sourcefolder set targetfolder to choose folder with prompt "Choose the Target folde +r location:" default location alias "MacHD:TargetFolder" set targetposix to POSIX path of targetfolder do shell script "/usr/bin/perl /PathToPerlScript &> '/Logs/Reprocesslo +g.txt'" & " -t " & targetposix & " -s " & sourceposix & "-c" & cfgpos +ix set nextdate to do shell script "date" & " +%y%m%d_%H%M%S" # some more code will go here to open the log file in console, so that + one can see the log updates in real time.

    Now, I can pass the arguments to my script, but it doesn't run in background. Hence, the next AppleScript statement doesn't execute until the perl script finishes execution.

    Since, then I have tried several quote combinations to make it work and I thought, I succeeded yesterday night but today morning, couldn't figure out what I did that made it work.

    Now, after several trials, I only face two outcomes:

    Either perl script runs in background(but doesn't accept the arguments passed to it) or it accepts the arguments passed to it, but doesn't run in background.

    Have hit a roadblock.

    Also, there is one more challenge with this method and that is I can run multiple instances of this script and each instance will create it's own log file. I want to be able to kill/stop any instance out of the several running ones. Challenge is how to do to it via Applescript so that user can select the exact instance that they want to stop.

    Any help/advice from anyone is appreciated. Thanks. PS: My perl script is not using Getopt:Long as of now, but I will look into it.

      This snippet reads a option, does the backgrounding and reads the pid of the current perlscript for killing it...

      set theWindowTitle to "PerlMonks" set theOption to text returned of (display dialog "Enter a sourceFolde +r:" & return default answer "" with title theWindowTitle) set thePerlscript to quoted form of (POSIX path of ((choose file with +prompt "Select a script:") as Unicode text)) set cmd to thePerlscript & " -S " & theOption & " &> /dev/null" & " & + echo $!" display dialog "Command: " & cmd with title theWindowTitle do shell script cmd set pid to the result display dialog "PID: " & pid with title theWindowTitle display dialog "Kill the proccess (" & pid & ")" buttons {"OK"} with t +itle theWindowTitle do shell script ("kill " & pid)

      I hope this helps a little bit to work it out...

      Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1014068]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2014-09-03 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls