InakaMac

Q: AppleScript no longer works after upgrading from Mountain Lion to Yosemite

Hey all,

 

I have an AppleScript I use for my business that automates a process I use daily. This script does the following automatically:

  • Creates a Job Folder inside a Client Folder
  • Job folder created is based on the date with an optional description
  • Creates subfolder inside the Job Folder for client original files, formatted files, final files, etc.
  • Highlights the Client folder in the label color red
  • Highlights the new Job folder also in the label color red
  • Sets a Reminder that this new job is in my ToDo List

 

This script is fantastic and works like a charm in Mountain Lion.

However, I upgraded a testing system to Yosemite, and my script fails.

 

I get the following error message:

 

"The variable thePath is not defined"

 

I'm stuck, and don't know what has changed from Mountain Lion to Yosemite that would cause this error.

I would really appreciate it if someone could review this script and perhaps let me know how to correct this error.

 

Here is my script:

 

on run {input, parameters}

  set thePath to the first item of the input -- just one

  tell (current date)
  set textMonth to text -2 thru -1 of ("0" & (it's month as integer)) -- leading zero
  set textYear to text -2 through -1 of (it's year as text)
  end tell

  set jobName to text returned of (display dialog "Please enter the three letter company code:" default answer "Three Letter Job Code")
  set jobNum to text returned of (display dialog "Please enter Job Number/Date:" default answer {textMonth & textYear & "01"})
  set jobLang to text returned of (display dialog "Please enter Project & Description:" default answer "SCH Card 1 PDF")
  set jobNumName to jobName & jobNum & " - " & jobLang

  try
  makeFolderStructure out of {jobNumName, {"Client Originals"}, {"Fax"}, {" FORMATTED FILES"}, {" FINAL DELIVERABLES"}, {" TRANSLATION FILE"}} at thePath
  on error errorMessage number errorNumber -- oops
  activate me
  display alert "Error " & errorNumber message errorMessage
  end try

  tell application "Finder"
  # parent folder
  set the label index of thePath to 2 -- 2 = red
  set the folder_name to the name of thePath

  # child folder
  get ((thePath as text) & jobNumName) as alias
  set the label index of the result to 2 -- 2 = red
  end tell


  -- Adds an item in the iCal ToDo list for this job
  set summarycal to folder_name & " - " & jobLang
  tell application "Reminders"
  set theList to list "Send to Translators"
  set newToDo to make new reminder with properties {name:summarycal, container:theList}
  end tell

  return thePath
end run


to makeFolderStructure out of someItem at someFolder
  (*
          make the folder structure defined in someItem at someFolder
          someList defines the structure:
                    nested list items create folders in the previous text item - {"A", {"B", {"C"}}} = /A/B/C
                    empty text items will create untitled folders
                    parameters -        someItem [mixed]: the folder structure
                                              someFolder [alias]: the destination folder
                    returns nothing
          *)
  set parentFolder to someFolder
  if class of someItem is list then
  repeat with anItem in someItem
  if class of anItem is list then -- add subfolder(s)
  makeFolderStructure out of anItem at someFolder
  else -- add a new child folder at the current parent
  tell application "Finder" to make new folder at parentFolder with properties {name:anItem}
  set someFolder to the result as alias
  end if
  end repeat
  else
  tell application "Finder" to make new folder at someFolder with properties {name:someItem}
  end if
end makeFolderStructure


 

Once again, any help would be GREATLY appreciated! I'm completely stuck.

Mac Pro, OS X Yosemite (10.10.5), null

Posted on May 26, 2016 11:14 PM

Close

Q: AppleScript no longer works after upgrading from Mountain Lion to Yosemite

  • All replies
  • Helpful answers

  • by red_menace,

    red_menace red_menace May 27, 2016 3:48 PM in response to InakaMac
    Level 6 (15,541 points)
    Desktops
    May 27, 2016 3:48 PM in response to InakaMac

    The script is meant to be run from within a Run AppleScript action in an Automator workflow, where the previous action is providing an input item for the variable.  If this is still the case, you might try loading your workflow into Automator and re-saving it.

  • by InakaMac,

    InakaMac InakaMac May 27, 2016 4:13 PM in response to red_menace
    Level 1 (4 points)
    Mac OS X
    May 27, 2016 4:13 PM in response to red_menace

    Red_menace,

     

    Thank you for your reply! Yes, I do have this script included in an Automator Workflow. I really think this has something to do with the way Yosemite uses new sandboxing or security. The original script in Yosemite actually did create the folders, and it does label them in red, but it fails on creating the ToDo.

     

    Thus,  I googled some things and altered the lines:

     

    FROM:

    1. tell application "Reminders" 
    2.   set theList to list "Send to Translators" 
    3.   set newToDo to make new reminder with properties {name:summarycal, container:theList} 
    4.   end tell

     

    TO:

    1. tell application "Reminders"
    2. set newremin to make new reminder
    3. set theList to list "Send to Translators"
    4. set name of newremin to summarycal
    5. set container to theList
    6. end tell

     

    And now everything works in Yosemite...BUT, a dialog box pops up still saying there's an error. I checked the Console in Yosemite and it mentioned text about a sandboxing error. Argh. Permissions issue? Just to be safe I made the Automator workflow file, read/write for all users, guests, etc.

     

    Even though the revised script works within Yosemite now (albeit with an error) it's still very odd, and perhaps a limitation of Yosemite's new security protocols and limitations?

  • by red_menace,Solvedanswer

    red_menace red_menace May 31, 2016 11:59 AM in response to InakaMac
    Level 6 (15,541 points)
    Desktops
    May 31, 2016 11:59 AM in response to InakaMac

    You can give Automator (or your Automator application) Accessibility permissions in the System Preferences >  Security & Privacy > Privacy tab, but it also looks like the Reminder part of your script should be something like:

     

    tell application "Reminders"
      tell list "Send to Translators"
        tell (make new reminder) to set its name to summarycal
      end tell
    end tell
    
  • by InakaMac,

    InakaMac InakaMac May 31, 2016 12:02 PM in response to red_menace
    Level 1 (4 points)
    Mac OS X
    May 31, 2016 12:02 PM in response to red_menace

    red_menace, you sir, are a genius! You figured out my problem!!

     

    I altered the script to the 5 lines you listed above, and it worked like a charm. I can't thank you enough, and I genuinely and sincerely think people like you make the internet community a better place. Thanks so much for taking the time out to help someone like me with this!! I would not have been able to figure this out on my own. Thanks again!!