At 6:38 pm +0900 7/10/02, Robin wrote:
>I'm trying to get perl scripts to run without having to go into the
>terminal or use a wrapper app.
>
>The script menu promises to be able to run any script from shell or
>perl to AppleScript.
This script will create a runnable script in Script Menu which will
open a text file announcing your success.
Paste this into BBEdit or whatever and run it to create the new
script. Note that scripts in the script menu must have a valid
shebang, have UNIX line endings and be executable. This script makes
sure all these conditions are met.
#!/usr/bin/perl
### Script path will put the script in the Script Menu
$scriptpath = "$ENV{HOME}/Library/Scripts/junk.pl";
### The contents of the script:
$script = << 'END_OF_SCRIPT';
#!/usr/bin/perl
$f = "/tmp/junk.txt" ;
open F, ">$f" or die $! ;
print F "\n\nSuccess at last ! Now run it from Script Menu." ;
close F ;
`open $f` ;
END_OF_SCRIPT
### In case you forgot that Mac line endings won't
### do, change all carriage returns to line feeds.
$script =~ s~\015~\012~g ;
open SCRIPT, ">$scriptpath" or die $! ;
### Write out the script
print SCRIPT $script ;
close SCRIPT ;
### Make the script executable and run it
`chmod +x $scriptpath ; perl $scriptpath` ;
>I've read that adding .command to a script name make scripts become
>double clickable processes running in the terminal.
If you change the extension of junk.pl you've just created to
..command and double-click it, it will launch the Terminal and the
script will run. Rather a clunky way to do things. A neater way
would be so use AppleScript or a shell script. Terminal does not
need to be invoked or running.
set scriptPath to "" & (path to scripts folder) & "junk.pl"
try
alias scriptPath
on error
return display dialog "no such file"
end try
set f to POSIX path of scriptPath
do shell script "perl " & f
>Neither seem to work for me - I have a perl script which I 'chmod'ed
>to make execable, and saved as script_name.command. Using wither of
>the above methods simply opens it in TextEdit, so I presume I'm
>missing something vital (and yes I tried logging out and in to reset
>the environment variables).
Probably just the line endings.
The same rules apply to shell scripts in the Script Menu.
JD