Can't set variable and option for perl script in AppleScript

Hi Folks,

I’m at my wits’ end. I’m trying ultimately to call a perl parsing tool that will split a text into parts, check data and then recombine the parts.

At this stage I’m just trying to write an AppleScript that will let me choose the file I need and then run the perl script with the correct option. Here is what I have:

set myFile to choose file with prompt “Project folder :” default location “/Users/bowjest/Documents/Projects/Texts”
do shell script “/usr/bin/perl /Users/bowjest/Documents/Scripts/target_extract.pl -e” & myFile

It has taken me ages to get to this point: the first line was easy, but everything I’ve tried so far in line 2 has just bombed. Now I’m getting the error:

“No option specified. You must specify -e or -m option. Exiting.”

But I have specified the option, but somehow my syntax must be off.

Can anyone offer some advice on where I’ve gone wrong?

Thanks,

Bowjest

Hi.

Please read the Posting guidelines before you post.

Have you tried adding a space after the -e parameter?

If set the myFile variable to lets say “/Users/bowjest/test.txt” and run your script

set myFile to choose file with prompt "Project folder :" default location "/Users/bowjest/Documents/Projects/Texts"
do shell script "/usr/bin/perl /Users/bowjest/Documents/Scripts/target_extract.pl -e" & myFile

It’ll run this on the 2nd line (and probably error out since -e/Users/bowjest/test.txt isn’t a parameter):

/usr/bin/perl /Users/bowjest/Documents/Scripts/target_extract.pl -e/Users/bowjest/test.txt

Now if you add a space:

set myFile to choose file with prompt "Project folder :" default location "/Users/bowjest/Documents/Projects/Texts"
do shell script "/usr/bin/perl /Users/bowjest/Documents/Scripts/target_extract.pl -e " & myFile

It’ll run this:

/usr/bin/perl /Users/bowjest/Documents/Scripts/target_extract.pl -e /Users/bowjest/test.txt

Hi Xeon3D,

Thanks for taking the time to reply.

Unfortunately, I’ve tried adding the space (as well as quite a few other things), but to no avail.

The only way I can get the script to be called and run is if I expressly set the full path:

do shell script "/usr/bin/perl /Users/Bowjest/Tools/Automator/ParseTMX/target_extract.pl -e /Users/Bowjest/project_save.tmx"

It doesn’t seem to like the variable I’ve set, using the same code to select a file in another app worked fine, so I really don’t understand why it’s not working here.

To be explicit: running the two lines of code:

  1. Enables me to navigate and select a file
  2. But the process then ends with an error message (different according to whether I put a space after -e or not, whether I’ve got myFile in quotes or not, etc.)

Is the problem with the way I’ve selected the file or assigned the variable in the first line:

set myFile to choose file with prompt "Project folder :" default location "/Users/bowjest/Documents/Projects/Texts"

Thanks,

Bowjest

Apparently it’s not possible to achieve what I’d like to do with AppleScript.

A shame really. I thought this was a versatile scripting language.