Problem passing multiple arguments to an AppleScript

Hi,

I have a problem passing multiple arguments to an AppleScript. My scripting environment is Mac OS X 10.4.11, my AppleScript version is 1.10.7 and I am working on a 1.8 GHz PowerPC G5.

I created a small sample script, which looks as follows:


on run {argitems}
    set argitems to argitems as list
    repeat with argitem in argitems
        set command to "logger " & quoted form of argitem
        do shell script command
    end repeat
end run

The script takes the arguments passed on the command line and logs them to the console with the logger command (I don’t use display dialog, as user interaction is not allowed when executing scripts with osascript).

Now when I execute the above script with the following osascript command, it won’t log all given arguments, but only the first one:

osascript osascript /Users/martin/Desktop/arglogger.scpt 'var1' 'var2' 'var2' -- will only log var1 on the console app...
Is this a known bug? I need to pass multiple file paths to a script at once and if this is not possible, then I am screwed :smiley: I really hope for your help!

Thanks in advance from Berlin!

Hi Martin,

from the osascript man page
Any arguments following the script will be passed as a list of strings to
the direct parameter of the ``run’’ handler. .

try this

on run argitems
    repeat with argitem in argitems
        set command to "logger " & quoted form of argitem
        do shell script command
    end repeat
end run

I tested

osascript ~/Desktop/test.scpt 'var1' 'var2' 'var3'

which logs all “variables”

Thanks so much StefanK, you really helped me out with this one!

Just removing the brackets around argitems solved the problem.

Best regards from Berlin!

You’re welcome :slight_smile:

Hey Martin,

When I read this I remembered one of your posts from last year showing how to accomplish this.
Is what you are talking about here different in some way that is not allowing display dialog?

Just checking, :slight_smile:

Craig

Yes. The company I am working for uses Mac OS X 10.4.11 only (last system, which features support for the classic environment). But unfortunately Tiger does not have the AppleScript Runner application installed mentioned in my post :frowning: Now I have to rewrite a lot of scripts to not use any user interaction…

I just tested this on 10.4.11 and it worked.
I put three arguments in from the command line and got three display dialogs.
The only thing returned was the last button.

There are some other examples people added to your post from last year.
You should check them out.

Does this work for you or am I missing something?


on run args
	repeat with anArg in args
		tell application "System Events"
			display dialog anArg
		end tell
	end repeat
end run

Hi Craig,

Many thanks for testing this for me! And yes, it helps me out. But I also have to rewrite a lot of scripts, as they are supposed to run silently on a server now, reading configuration files instead of getting interactive user input.

Greetings from sunny Berlin!