Search code examples
applescriptadobe-illustrator

Error opening illustrator file with Applescript


I am trying to open and save an illustrator file based on its folder structure, but for some reason I keep getting this error:

error "Adobe Illustrator got an error: an Illustrator error occurred: -54 (' ˇˇˇ')" number 1200

Along with the message:

 Illustrator couldn't open this file as it may be locked or in use

Well its not locked because I can open it manually, and it definitely wasn't in use at the time. Below is my code, please help if you can :)

 set inputFolder to choose folder with prompt "Select the folder"
 tell application "Finder" to set jobNumber to name of inputFolder
 set aiPath to inputFolder & "Assembly:" & jobNumber & ".ai" --path of outlined file
 set olPath to inputFolder & "Deliverables:" & jobNumber & "_OL.ai" --path of outlined file

tell application id "com.adobe.Illustrator"
activate
open aiPath without dialogs

convert to paths (every text frame of current document) --convert text to paths
save current document in file olPath as Illustrator with options {class:Illustrator save options, compatibility:Illustrator 15, font subset threshold:0.0, embed linked files:true, save multiple artboards:false} --save an outlined copy to Deliverables with name + _OL.ai 

end tell

*****edit******

I attempted to fix it by adding the text to the alias while it was a string, and then converting it to an alias.

For some reason this works with the 1st path, but when it reaches the second it says "cannot make alias into type alias" I am very confused, please help :/

 set inputFolder to choose folder with prompt "Select the folder"
 tell application "Finder" to set jobNumber to name of inputFolder
 set temp to inputFolder & "Assembly:" & jobNumber & ".ai" as string --path of outlined file
 set aiPath to temp as alias
 set temp to inputFolder & "Deliverables:" & jobNumber & "_OL.ai" --path of outlined file
 set olPath to temp as alias

 tell application id "com.adobe.Illustrator"
activate
open file aiPath without dialogs

convert to paths (every text frame of current document) --convert text to paths
save current document in file olPath as Illustrator with options {class:Illustrator save options, compatibility:Illustrator 15, font subset threshold:0.0, embed linked files:true, save multiple artboards:false} --save an outlined copy to Deliverables with name + _OL.ai 

   end tell

Solution

  • Your variable "inputFolder" is an alias and they don't normally like having text added to them. Try making it a string. Try this:

     set inputFolder to choose folder with prompt "Select the folder"
     set inputFolder to inputFolder as string
     tell application "Finder" to set jobNumber to name of folder inputFolder
     set aiPath to inputFolder & "Assembly:" & jobNumber & ".ai" --path of outlined file
     set olPath to inputFolder & "Deliverables:" & jobNumber & "_OL.ai" --path of outlined file
    
    tell application id "com.adobe.Illustrator"
    activate
    open aiPath without dialogs
    
    convert to paths (every text frame of current document) --convert text to paths
    save current document in file olPath as Illustrator with options {class:Illustrator save options, compatibility:Illustrator 15, font subset threshold:0.0, embed linked files:true, save multiple artboards:false} --save an outlined copy to Deliverables with name + _OL.ai 
    
    end tell
    

    Update

    Check your file path for "olPath" exists. AI will not make new folder from what I am remembering. If I take your save command and change it to save on my desktop it works fine.

    set FilePath to ((path to desktop) as string) & "TestFile.ai"
    tell application id "com.adobe.Illustrator"
        activate
        save current document in file FilePath as Illustrator with options {class:Illustrator save options, compatibility:Illustrator 15, font subset threshold:0.0, embed linked files:true, save multiple artboards:false} --save an outlined copy to Deliverables with name + _OL.ai 
    
    end tell
    

    Update 2

    This works for me.

    set inputFolder to choose folder with prompt "Select the folder"
    set inputFolder to inputFolder as string
    tell application "Finder" to set jobNumber to name of folder inputFolder
    set aiPath to inputFolder & "Assembly:" & jobNumber & ".ai" --path of outlined file
    set olPath to inputFolder & "Deliverables:" & jobNumber & "_OL.ai" --path of outlined file
    
    tell application id "com.adobe.Illustrator"
        activate
        open file aiPath without dialogs
    
        convert to paths (every text frame of current document) --convert text to paths
        save current document in file olPath as Illustrator with options {class:Illustrator save options, compatibility:Illustrator 15, font subset threshold:0.0, embed linked files:true, save multiple artboards:false} --save an outlined copy to Deliverables with name + _OL.ai 
    
    end tell