Re: Cron Progress Bar in OSX
On Monday, Oct 20, 2003, at 17:03 Europe/London, Chris Nandor wrote: In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Thane Norton) wrote: One of my personal favorites is to use a here document to supply the code for an applescript via osascript. i.e. my $script = 'APPLESCRIPT'; tell application Finder display dialog Hello World end tell APPLESCRIPT local *script_to; local *script_from; local *script_error; my $pid = open3(*script_to, *script_from, *script_error, /usr/bin/osascript) or die Couldn't open osascript; print script_to $script; close script_to; A much more efficient method would be to use one of the XS AppleScript methods, including MacPerl::DoAppleScript() in Mac::Carbon, applescript() in Mac::OSA::Simple (requires Mac::Carbon), and RunAppleScript from Mac::AppleScript. Also system('open', applescript.app) seems to run a tad faster (?) than RunAppleScript although it is not AFAIK possible to take Perl variables into and out of AS that way. In passing I suspect a minor bug with RunAppleScript: in the example given the Perl script dies even thought the AppleScript succeeds. Coming back to the original question in this thread: CronniX is a very nice application which one would be hard pushed to better. 'CamelBones' looks attractive for the kind of GUI one used to be able to do so easily with MacPerl. I have not found any documentation apart from the three How To's on the CB site. Can anyone help? Alan Fry
Re: Cron Progress Bar in OSX
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Dan Sugalski) wrote: FWIW, you can pop up progress bars from perl, though it does require turning the perl program into a Cocoa app with Sherm's CamelBones framework. (I think the Mac::Carbon module(s?) may do this as well, but you may or may not still have to turn the program into an application) Mac::Carbon (port of toolbox modules from MacPerl to Mac OS X) does not contain any GUI modules. The best you can do is control other GUI programs with it. -- Chris Nandor [EMAIL PROTECTED]http://pudge.net/ Open Source Development Network[EMAIL PROTECTED] http://osdn.com/
Re: Cron Progress Bar in OSX
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Thane Norton) wrote: One of my personal favorites is to use a here document to supply the code for an applescript via osascript. i.e. my $script = 'APPLESCRIPT'; tell application Finder display dialog Hello World end tell APPLESCRIPT local *script_to; local *script_from; local *script_error; my $pid = open3(*script_to, *script_from, *script_error, /usr/bin/osascript) or die Couldn't open osascript; print script_to $script; close script_to; A much more efficient method would be to use one of the XS AppleScript methods, including MacPerl::DoAppleScript() in Mac::Carbon, applescript() in Mac::OSA::Simple (requires Mac::Carbon), and RunAppleScript from Mac::AppleScript. my $result = DoAppleScript($script); -- Chris Nandor [EMAIL PROTECTED]http://pudge.net/ Open Source Development Network[EMAIL PROTECTED] http://osdn.com/
Re: Cron Progress Bar in OSX
At 9:48 am -0600 14/10/03, Doug McNutt wrote: At 00:16 +0100 10/14/03, Alan Fry wrote: do shell script /Users/alanfry/Desktop/backatcha.pl results in the error: ...backatcha.pl:perl:bad interpreter:Permission denied do shell script is misnamed as are a lot of other commands in AppleScript. What it really means is Tell the OS to execute something that has been flagged as executable by setting the x bit in its permissions for the user who is making the request. It doesn't matter whether the file pointed to is a shell script or not though AppleScript does invoke the bash shell to manage the execution and can accept bash commands directly. Compiled C code and perl scripts with a #! line are equally executable but you must set that x bit. The failure you report is that you didn't have execute permission. Right. JD pointed that out in his message -- but I am grateful for the amplification. Terminal is the easy way. The command is chmod 777 path_to_file which actually opens it up completely to anyone. The rightmost bit in each octal digit is the x bit for user, group, and world. man chmod for more. It would be nice if Finder allowed access to the x bit but it doesn't. It would be nice if Finder would execute a double-clicked file with the x bit set but. . . Steve?Is it possible to write an AppleScript to do that? Expanding James Reynolds idea (13th Oct) a little I have got the following to work: AppleScript (application) as file /Users/alanfry/Droplets/ChangeMode.app on open myFile set myPath to POSIX path of myFile display dialog File: myPath return Set new permissions as: default answer 0755 set newMode to text returned of result set newPath to do shell script /Users/alanfry/Droplets/PerlScripts/ChangeMode.txt \ myPath \ \ newMode \ display dialog result buttons {QUIT} default button 1 end open Perl script as file /Users/alanfry/Droplets/PerlScripts/ChangeMode.txt #!/usr/bin/perl my $myFile = $ARGV[0]; my $perms = $ARGV[1]; $perms = oct $perms; my @list = stat($myFile); print File: $myFile\n; printf %-32s%o\n, Previous permissions were:, $list[2]; chmod $perms, $myFile; @list = stat($myFile); printf %-30s%o\n, Current permissions are now:, $list[2]; On dropping any file onto the applet a dialog is put up asking for the new permissions (with 0755 as default suggestion). After clicking the 'OK' button the perl script changes the mode and puts up another AS dialog confirming the full-path file name, the previous permissions and the new current permissions. Comments would be very welcome. I suppose folders should be excluded and things like zip disks at the very least. Whether it's any improvement on typing 'chmod 0777 file' in the Terminal I'm not sure... Alan Fry
Re: Cron Progress Bar in OSX
At 12:16 am +0100 14/10/03, Alan Fry wrote: The script runs fine from the Terminal with the command 'perl' however. What am I missing? Read my message of Thu, 9 Oct 2003 12:40:33 +0100
Re: Cron Progress Bar in OSX
At 9:00 am -0600 13/10/03, James Reynolds wrote: This is one way to do it: on open these_items repeat with this_item in these_items set the_path to POSIX path of this_item set result to do shell script /Users/james/backatcha.pl \ the_path \ display dialog result end repeat end open Save as an application. And /Users/james/backatcha.pl is: #!/usr/bin/perl print I got: $ARGV[0]; Thank you very much for that suggestion -- it is just the sort of thing I was hoping for. But I have a bug somewhere -- just a simple AS do shell script /Users/alanfry/Desktop/backatcha.pl results in the error: ...backatcha.pl:perl:bad interpreter:Permission denied The script runs fine from the Terminal with the command 'perl' however. What am I missing? Alan I'm not sure. You might try putting the exact Terminal command inside of the do shell script command, like this: do shell script perl /Users/alanfry/Desktop/backatcha.pl or you might make the file /Users/alanfry/Desktop/backatcha.pl executable like this: chmod u+x /Users/alanfry/Desktop/backatcha.pl -- Thanks, James Reynolds University of Utah Student Computing Labs [EMAIL PROTECTED] 801-585-9811
Re: Cron Progress Bar in OSX
Riccardo Perotti wrote: DropScript Don't have an url, but I'm sure you can find it in Version Tracker. Or from my earlier post ;) http://www.mit.edu/people/wsanchez/software/ Pete
Re: Cron Progress Bar in OSX
At 00:16 +0100 10/14/03, Alan Fry wrote: do shell script /Users/alanfry/Desktop/backatcha.pl results in the error: ...backatcha.pl:perl:bad interpreter:Permission denied do shell script is misnamed as are a lot of other commands in AppleScript. What it really means is Tell the OS to execute something that has been flagged as executable by setting the x bit in its permissions for the user who is making the request. It doesn't matter whether the file pointed to is a shell script or not though AppleScript does invoke the bash shell to manage the execution and can accept bash commands directly. Compiled C code and perl scripts with a #! line are equally executable but you must set that x bit. The failure you report is that you didn't have execute permission. Terminal is the easy way. The command is chmod 777 path_to_file which actually opens it up completely to anyone. The rightmost bit in each octal digit is the x bit for user, group, and world. man chmod for more. It would be nice if Finder allowed access to the x bit but it doesn't. It would be nice if Finder would execute a double-clicked file with the x bit set but. . . Steve? Is it possible to write an AppleScript to do that? -- -- There are 10 kinds of people: those who understand binary, and those who don't --
Re: Cron Progress Bar in OSX
At 9:00 am -0600 13/10/03, James Reynolds wrote: This is one way to do it: on open these_items repeat with this_item in these_items set the_path to POSIX path of this_item set result to do shell script /Users/james/backatcha.pl \ the_path \ display dialog result end repeat end open Yippee! I have got this to work, and now, with a few minor variations have a nice little applet on which you can drop a 'pod' file and get a 'pdf' version in return. I am most grateful for all the very helpful contributions from so many folk in the last day or so. Many thanks, Alan
Re: Cron Progress Bar in OSX
Tue, 14 Oct 2003 08:38:22 +0100 John Delacour wrote: At 12:16 am +0100 14/10/03, Alan Fry wrote: do shell script /Users/alanfry/Desktop/backatcha.pl results in the error: ...backatcha.pl:perl:bad interpreter:Permission denied The script runs fine from the Terminal with the command 'perl' however. What am I missing? You have two choices: do shell script perl quoted form of pathname or, if the permissions are set to executable and the script has the shebang (chmod pathname +x), do shell script ./Users/alanfry/Desktop/backatcha.pl for example /tmp/test.pl reads #!/usr/bin/perl print hello\n do shell script ./tmp/test.pl -- hello Running a 'chmod' fixes the problem and both methods above now work. However I don't seem to need the dot before the path (?) in the case where the file is 'executable'. Many thanks, Alan
Re: Cron Progress Bar in OSX
At 10:05 pm +0100 14/10/03, Alan Fry wrote: Running a 'chmod' fixes the problem and both methods above now work. However I don't seem to need the dot before the path (?) in the case where the file is 'executable'. You will if its not in your PATH. Compare these three scripts. Since tmp.pl is not in your path, you will get an error with the third: do shell script cd /tmp; perl -e ' $f=qq~tmp.pl~; open F, qq~$f~ ; print F qq~#!/usr/bin/perl\\nprint qq(hello\\n)~ ' ; chmod +x tmp.pl ; ./tmp.pl do shell script cd /tmp; perl -e ' $f=qq~tmp.pl~; open F, qq~$f~ ; print F qq~#!/usr/bin/perl\\nprint qq(hello\\n)~ ' ; chmod +x tmp.pl ; perl tmp.pl do shell script cd /tmp; perl -e ' $f=qq~tmp.pl~; open F, qq~$f~ ; print F qq~#!/usr/bin/perl\\nprint qq(hello\\n)~ ' ; chmod +x tmp.pl ; tmp.pl
Re: Cron Progress Bar in OSX
James Reynolds wrote Thu, 9 Oct 2003 08:38:24 -0600: I have been writing an extremely lightweight Cocoa utility (10 lines of code about) that displays a dialog box with a barber pole and some message. It isn't quite done yet (I don't like the way it looks). It is intended to be launched by a perl script. I would be very interested in giving that a try on a 'test-bed' basis if that appeals to you. Alan
Re: Cron Progress Bar in OSX
Doug McNutt wrote Thu, 9 Oct 2003 05:40:58 -0600: At 10:46 +0100 10/9/03, Alan Fry wrote: I have a MacPerl script I am trying to transfer from OS9 to OSX. There are two problems: cron cron needs to point, with a full path, to an executable, That is, something with the x permission bit set. That can be /usr/bin/perl with arguments pointing to a perl script as text or it can be to the script itself if it begins with a #!/usr/bin/perl line and has been made executable with a chmod. Remember that your .login and other initializations, $PATH in particular, will not be set up for you by cron. cron can open an AppleScript APPL (man open) but if all it is used for is to start up MacPerl you won't need it. Except for GUI things that involve Finder like drag and drop you'll be better off replicating the AppleScript tasks in a shell script. Osascript is available for simple AppleScript-like things from a shell. Many thanks Doug for your comments, which I have carefully filed against the day I shall understand what you're saying. My personal problem is total ignorance of Unix and all its manifold works. I have a learning curve to negotiate, to say the least. At the moment I am merely chipping away like Fred Flintstone at a paleolithic Terminal window, getting nowhere fast. What I miss most is the MacPerl droplet, on which you could drop a file, extract the path (into ARGV) and do something with the file. For instance I have a droplet to decode Base64 -- drop and bingo there is the decoded file. And similarly with more complicated issues like translating a 'pod' file to 'pdf'. Is there anyway one can get back to this functionality in MacOS X? Experiments with AppleScript have not been rewarding. Sure, you can write an applet which will extract the full path name from a file dropped on it. But the path is the old Mac-style colon separated directory path. What can you do with that? Even assuming you could translate the Mac-style path to a Unix-style path (in AppleScript!), how can you pass the path to a Perl script? I have tried telling application Terminal to do a perl script pushing a valid path into @ARGV and then to run a second perl script to see what is in the ARGV list. The answer is always nothing. So I am stuck -- wondering if things might perhaps be more cheerful with WinPerl? Can anybody cheer me up? Alan
Re: Cron Progress Bar in OSX
At 12:03 +0100 10/13/03, Alan Fry wrote: What I miss most is the MacPerl droplet, on which you could drop a file, extract the path (into ARGV) and do something with the file. For instance I have a droplet to decode Base64 -- drop and bingo there is the decoded file. I do use AppleScript for that kind of thing. I'll try to find some samples for you. In the meantime check this out. It is a droplet to replace line ends in dropped files but ignore that and have a look at the source. ftp://ftp.macnauchtan.com/Software/LineEnds/ ftp://ftp.macnauchtan.com/Software/LineEnds/FixEndsFolder.sit (52 kB) It's not perl but it does show a way to make AS droplets pass filenames and arguments to executable shell tools. You should also learn about POSIX path of and quoted form of commands in AS. And similarly with more complicated issues like translating a 'pod' file to 'pdf'. Wasn't that corncob great? I changed the creator code of all .pm's to match, but all that is repaired in OS neXt.. Can anybody cheer me up? -- Applescript syntax is like English spelling: Roughly, but not thoroughly, thought through.
Re: Cron Progress Bar in OSX
One of my personal favorites is to use a here document to supply the code for an applescript via osascript. i.e. --- #!/bin/perl -w use strict; use IPC::Open3; my $script = 'APPLESCRIPT'; tell application Finder display dialog Hello World end tell APPLESCRIPT # using a here document can mess with the debugger line numbering, # so include a line comment for it #line 15 local *script_to; local *script_from; local *script_error; my $pid = open3(*script_to, *script_from, *script_error, /usr/bin/osascript) or die Couldn't open osascript; print script_to $script; close script_to; while (script_from) { print result: $_\n; } close script_from; while (script_error) { print error: $_\n; } close script_error; -- On 10/13/03 6:58 AM, Doug McNutt [EMAIL PROTECTED] wrote: I do use AppleScript for that kind of thing. I'll try to find some samples for you.
Re: Cron Progress Bar in OSX
FWIW, you can pop up progress bars from perl, though it does require turning the perl program into a Cocoa app with Sherm's CamelBones framework. (I think the Mac::Carbon module(s?) may do this as well, but you may or may not still have to turn the program into an application) You can fire full-scale .apps off via cron--just dig through the bundle and find the real executable, and use its full pathname. (No relative paths, and no invocations via PATH env vars. Cocoa does *not* like that) For example, to fire off emacs which is living in /Applications you'd just invoke /Applications/Emacs.app/Contents/MacOS/Emacs. You can even pass in parameters, which'll show in @ARGV for perl programs. I suppose it'd be possible to build a progress app that took test-style output (you know, the 18 tests, ok 1, ok 2 stuff) from the child process and did the progress bar while the child did its thing and spat its status info to its stdout... Dan
Re: Cron Progress Bar in OSX
Doug McNutt wrote Thu, 9 Oct 2003 05:40:58 -0600: At 10:46 +0100 10/9/03, Alan Fry wrote: I have a MacPerl script I am trying to transfer from OS9 to OSX. There are two problems: cron cron needs to point, with a full path, to an executable, That is, something with the x permission bit set. That can be /usr/bin/perl with arguments pointing to a perl script as text or it can be to the script itself if it begins with a #!/usr/bin/perl line and has been made executable with a chmod. Remember that your .login and other initializations, $PATH in particular, will not be set up for you by cron. cron can open an AppleScript APPL (man open) but if all it is used for is to start up MacPerl you won't need it. Except for GUI things that involve Finder like drag and drop you'll be better off replicating the AppleScript tasks in a shell script. Osascript is available for simple AppleScript-like things from a shell. Many thanks Doug for your comments, which I have carefully filed against the day I shall understand what you're saying. My personal problem is total ignorance of Unix and all its manifold works. I have a learning curve to negotiate, to say the least. At the moment I am merely chipping away like Fred Flintstone at a paleolithic Terminal window, getting nowhere fast. What I miss most is the MacPerl droplet, on which you could drop a file, extract the path (into ARGV) and do something with the file. For instance I have a droplet to decode Base64 -- drop and bingo there is the decoded file. And similarly with more complicated issues like translating a 'pod' file to 'pdf'. Is there anyway one can get back to this functionality in MacOS X? Experiments with AppleScript have not been rewarding. Sure, you can write an applet which will extract the full path name from a file dropped on it. But the path is the old Mac-style colon separated directory path. What can you do with that? Even assuming you could translate the Mac-style path to a Unix-style path (in AppleScript!), how can you pass the path to a Perl script? I have tried telling application Terminal to do a perl script pushing a valid path into @ARGV and then to run a second perl script to see what is in the ARGV list. The answer is always nothing. This is one way to do it: on open these_items repeat with this_item in these_items set the_path to POSIX path of this_item set result to do shell script /Users/james/backatcha.pl \ the_path \ display dialog result end repeat end open Save as an application. And /Users/james/backatcha.pl is: #!/usr/bin/perl print I got: $ARGV[0]; -- Thanks, James Reynolds University of Utah Student Computing Labs [EMAIL PROTECTED] 801-585-9811
Re: Cron Progress Bar in OSX
At 9:00 am -0600 13/10/03, James Reynolds wrote: This is one way to do it: on open these_items repeat with this_item in these_items set the_path to POSIX path of this_item set result to do shell script /Users/james/backatcha.pl \ the_path \ This will break if there happens to be a in the pathname. 'quoted form of' POSIX path of... takes care of all that. What is needed is perl some.pl f1 f2 f3 f4 so only one Apple event is needed; the file list can be build as a string and passed with a single do shell script call. JD
Re: Cron Progress Bar in OSX
FWIW, you can pop up progress bars from perl, though it does require turning the perl program into a Cocoa app with Sherm's CamelBones framework. (I think the Mac::Carbon module(s?) may do this as well, but you may or may not still have to turn the program into an application) You can fire full-scale .apps off via cron--just dig through the bundle and find the real executable, and use its full pathname. (No relative paths, and no invocations via PATH env vars. Cocoa does *not* like that) For example, to fire off emacs which is living in /Applications you'd just invoke /Applications/Emacs.app/Contents/MacOS/Emacs. You can even pass in parameters, which'll show in @ARGV for perl programs. I suppose it'd be possible to build a progress app that took test-style output (you know, the 18 tests, ok 1, ok 2 stuff) from the child process and did the progress bar while the child did its thing and spat its status info to its stdout... Dan http://www.ihook.org I'm working on a similar app but is less functional so that it launches faster. -- Thanks, James Reynolds University of Utah Student Computing Labs [EMAIL PROTECTED] 801-585-9811
Re: Cron Progress Bar in OSX
On 10/13/2003 06:03 AM, Alan Fry [EMAIL PROTECTED] wrote: Doug McNutt wrote Thu, 9 Oct 2003 05:40:58 -0600: What I miss most is the MacPerl droplet, on which you could drop a file, extract the path (into ARGV) and do something with the file. For instance I have a droplet to decode Base64 -- drop and bingo there is the decoded file. And similarly with more complicated issues like translating a 'pod' file to 'pdf'. Is there anyway one can get back to this functionality in MacOS X? ... Can anybody cheer me up? Alan DropScript Don't have an url, but I'm sure you can find it in Version Tracker. Cheer Up! Riccardo -- mailto:perotti(at)pobox.com http://www.riccardoperotti.com
Re: Cron Progress Bar in OSX
At 9:00 am -0600 13/10/03, James Reynolds wrote: This is one way to do it: on open these_items repeat with this_item in these_items set the_path to POSIX path of this_item set result to do shell script /Users/james/backatcha.pl \ the_path \ This will break if there happens to be a in the pathname. 'quoted form of' POSIX path of... takes care of all that. What is needed is perl some.pl f1 f2 f3 f4 so only one Apple event is needed; the file list can be build as a string and passed with a single do shell script call. JD How about: on open these_items set args to repeat with this_item in these_items set args to args quoted form of POSIX path of this_item end repeat set result to do shell script /Users/james/backatcha.pl args display dialog result end open Save as an application. And /Users/james/backatcha.pl is: #!/usr/bin/perl foreach $i (@ARGV) { print I got: $i\n; } -- Thanks, James Reynolds University of Utah Student Computing Labs [EMAIL PROTECTED] 801-585-9811
Re: Cron Progress Bar in OSX
At 9:00 am -0600 13/10/03, James Reynolds wrote: This is one way to do it: on open these_items repeat with this_item in these_items set the_path to POSIX path of this_item set result to do shell script /Users/james/backatcha.pl \ the_path \ display dialog result end repeat end open Save as an application. And /Users/james/backatcha.pl is: #!/usr/bin/perl print I got: $ARGV[0]; Thank you very much for that suggestion -- it is just the sort of thing I was hoping for. But I have a bug somewhere -- just a simple AS do shell script /Users/alanfry/Desktop/backatcha.pl results in the error: ...backatcha.pl:perl:bad interpreter:Permission denied The script runs fine from the Terminal with the command 'perl' however. What am I missing? Alan
Cron Progress Bar in OSX
I have a MacPerl script I am trying to transfer from OS9 to OSX. There are two problems: cron and a progress bar. Regarding 'cron', the perl script is kicked off by an AS application, so the problem really is how to get the AS application to run at specific times. The second problem is how to replace the MacPerl Progress Bar in OSX perl. I would be grateful for guidance. Alan Fry
Re: Cron Progress Bar in OSX
At 10:46 am +0100 9/10/03, Alan Fry wrote: I have a MacPerl script I am trying to transfer from OS9 to OSX. There are two problems: cron and a progress bar. Regarding 'cron', the perl script is kicked off by an AS application, so the problem really is how to get the AS application to run at specific times. The second problem is how to replace the MacPerl Progress Bar in OSX perl. As to the scheduling, if you're not going to use cron or some third party utility to launch the application, then you can run the application as stay-open with an idle handler such as the script below. As to the progress bar, I'd need to know what you mean. property _times : {06:45am, 12:20pm, 12:35pm} property _midnight : 0 ---idle --uncomment to test on idle set _now to (current date) - (get date _midnight) repeat with t in _times set _alarm to (date t) - (get date _midnight) set _difference to _alarm - _now if _difference is less than 0 and ¬ _difference is greater than -2 * minutes then doThis() return 2 * minutes --(rerun idle in 2 minutes) end if end repeat _alarm end idle on doThis() do shell script perl -e ' $f = qq~/tmp/date.txt~ ; open F, qq~$f~ ; print F scalar localtime ; `open -e $f` ; ' end doThis