Parse string without quotes

Ok first of all id like to welcome myself in the forums which have been helping me alot in scripting for ages :smiley:

Now to my problem:
I wrote this code:

tell application "Finder" 
      make new folder at desktop with properties {name:"OUTPUT_JPEGS_FROM_PDF"} 
   end try 
   set myFolder to choose folder with prompt "Bitte Eingabeordner wählen!" 
   set myFileList to items in myFolder 
   set myFolderout to choose folder with prompt "Bitte Ausgabeordner wählen" 
   set dpires to text returned of (display dialog "Bitte DPI angeben:" default answer "72") as integer 
   set thecropboxentry to choose from list {"crop box", "media box", "trim box", "bleed box", "art box"} 
   set thecropbox to thecropboxentry as string 
   repeat with k from 1 to length of myFileList 
      my myAction(item k of myFileList as alias, myFolderout, dpires, thecropbox) 
   end repeat 
   display dialog "Done" 
end tell 

on myAction(myFile, myFolderout, dpires, thecropbox) 
   with timeout of 86400 seconds 
      tell application "Adobe Photoshop CS4" 
         open myFile with options {resolution:dpires, crop page:thecropbox} 
         save current document in alias myFolderout as JPEG with options {quality:12} appending lowercase extension copying 1 
         close current document without saving 
      end tell 
   end timeout 
end myAction 

Now the problem part is this one:

crop page:thecropbox

this results in photoshop getting the one i chosen from the list as so: crop page:"media box"
which it cannot handle. Photoshop needs the string without quotes, so it can handle it as an option and not a text string like so: crop page:media box
Now question is, how to parse the chose from list result as an option type string without quotes?



You need to do something like this:

if thecropbox = “crop box” then
set thecropbox to crop box
else if the cropbox = “media box” then

Ok cant test this just now, but is it really possible to set a variable to a command? Wont it then just say crop box like unknown command??

Well crop box is a not a command but a class and you can put classes in variables. The limitation of using a class in a variable is that you can only use them as a value for something. In your case crop box class is a value of property crop page of class open options wich means that crop box is used as a value.

set x to {class:integer} --lets pretend this is the list with "open options"
set c to string
set class of x to c --set another class to property
return x --result: {class:string}

ok, i will test this tomorrow at the office, thank you!

It’s not a class but an enumeration – a sort of application-defined constant.

Ok if i try this, it marks me this line set thecropbox to crop box
and tells me:

Es wurde žZeilenende, etc." erwartet, aber ein žIdentifier" wurde gefunden.

Sorry its german :confused:

i think it means in english something like it was expected a line end but an identifier was found, and i guess this is because i am using this command out of the “tell photoshop” block right?

Because the problem is, if i am going to use it in the Photoshop block in the lower handler section, it is going to as me for the crop box everytime it repeats the handler with a new file.
If i want to parse the option to the handler, i would have to set the variable just like now in the upper section, not in the handler, which then again results in the problem i have now.
Im going to test if i can add a “tell photoshop” block in the upper section, and will post this here!

OK got it to work, i used
tell app “photoshop” to set thecropbox to crop box
and this got me the variable gotten to set to the command not a string, because photoshop knows about the crop box “command”
now i am running in another problem…

i now have the code as such:

set thecropboxentry to choose from list {"1. crop box", "2. media box", "3. trim box", "4. bleed box", "5. art box"}
tell application "Adobe Photoshop CS4"
        if thecropboxentry is "1. crop box" then
            set thecropbox to crop box
        else if thecropboxentry is "2. media box" then
            set thecropbox to media box
        else if thecropboxentry is "3. trim box" then
            set thecropbox to trim box
        else if thecropboxentry is "4. bleed box" then
            set thecropbox to bleed box
        else if thecropboxentry is "5. art box" then
            set thecropbox to art box
        end if
    end tell

and it now tells me the variable “thecropbox” is not defined when it wants to launch the handler and it markes me this line, concreter the “thecropbox” in this line:

my myAction(item k of myFileList as alias, myFolderout, dpires, thequal, thecropbox)

why is it not defined? i defined it with the choose from list, and then converted the string to a class with the photoshop if part… not?

haha ok i just fixed myself

i forgot this little but very important line:

set thecropboxentry to thecropboxentry as string

this line converts the list item from choose from list to a string (this i guess is the safer way, because i hate using “as string” behind the choose from list part)
Working now, thank you!

Well I was looking for word and didn’t know it applescript uses the term enum too.