Select Path Apple Script Now Different Under Lion...help?
I have an AppleScript that I had been using with Leopard and Snow Leopard and it performed beatuifully.
Unfortuntely, something has changed in Lion and after upgrading my script doesn't work as desired. I'm guessing it has to be based on the way Lion "selects" a folder in the Finder, perhaps due to column view.
My original process would allow me to create a new folder in the Finder in the column view, or just select a folder that was already created. Once that folder was selected in the Finder, I could pull down the Script Menu to select this script.
For example if my path is:
Macintosh HD > (here is where I would create a folder like "Apple" for example)
If this was a project for a client I had worked for in the past, I would not need a new folder and instead would just highlight their already exisiting folder in the Finder (column view) and then select the script as usual.
The script would then create a series of subfolders within the selected folder, and also create an iCal To Do list name item based on the selected folder, and highlight the Finder folder in red. The selected folder ("Apple" for example) would be the name of the To Do item, etc. So in iCal it would have a new ToDo list called "Apple - Canada 1" etc.
So when launched, my script would create a folder and iCal ToDo something like this in bold:
Macintosh HD > Apple > APL011201 - Canada 1
This worked great....until Lion. 😟
Lion seems to have changed the way it selects folders. I always use the column view in the Finder. (I hope that's the exact name. It's NOT the icon, list, or "image" view.) It's the three-column view.
The reason I bring this up is that in Lion if I used the list view the script works. But in column view my script doesn't crash, but instead of creating a folder in the desired area above, Lion creates it in the root of the hard drive. So the folder is created here, outside the selected folder:
Macintosh HD > APL011201 - Canada 1
It also ruins the iCal ToDo list as well so that instead of "Apple - Canada 1" being in the ToDo, the ToDo is "Macintosh HD - Canada 1".
It also now highlights the hard drive in red, instead of the job folder.
This all seems to be based on Lion not knowing the selected folder, so it performs the script in the incorrect path.
Also, the error is inconsistent. The script works as desired sometimes in Lion, even in teh column view, but mostly does not and will create the path incorrectly (shown above) in the root directory of the hard drive.
I'm racking my brain and can't solve this. Anyone see anything I can alter in regasrds to the Finder selection/path to get this script working again 100% under Lion? Any help is appreicated.
Below is my script:
-- make a folder structure at the currently selected Finder item
tell application "Finder" to try -- get the current selection
set ThePath to the first item of (get selection)
if the last character of (ThePath as text) is not ":" then -- a file
set ThePath to the container of ThePath
end if
on error -- default to the desktop
set ThePath to (get path to desktop folder)
end try
set JobName to text returned of (display dialog "Please enter the three letter company code:" default answer "Three Letter Job Code")
set incomingDate to (current date)
set numYear to year of incomingDate as number
set numMonth to month of incomingDate as number
set textMonth to (text -2 thru -1 of ("0" & numMonth as string))
set textYear to text -2 through -1 of (numYear as string)
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 "Ad 1 Canada")
set JobNumName to JobName & JobNum & " - " & JobLang
try
MakeFolderStructure out of {JobNumName, {"Client Originals"}, {"Fax"}, {" FORMATTED FILES"}, {" FINAL DELIVERABLES"}, {" WORD FILE"}} at ThePath
on error ErrorMessagenumberErrorNumber-- oops
activate me
display alert "Error " & ErrorNumbermessageErrorMessage
end try
to MakeFolderStructureout ofSomeItematSomeFolder
(*
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)
MakeFolderStructureout ofAnItematSomeFolder
else -- add a new child folder at the current parent
tell application "Finder" to makenewfolderatParentFolderwith properties {name:AnItem}
set SomeFolder to the result as alias
end if
end repeat
else -- add a new (potential) parent folder
tell application "Finder" to makenewfolderatSomeFolderwith properties {name:AnItem}
set ParentFolder to the result as alias
end if
end MakeFolderStructure
tell application "Finder"
set ParentFolder to selection as alias
set the label index of ParentFolder to 2 -- 2 = red
-- Adds an item in the iCal ToDo list for this job
--get the name of the folder
set the folder_name to the name of ParentFolder
set summarycal to folder_name & " - " & JobLang
tell application "iCal"
tell calendar "Waiting for Review"
makenewtodowith properties {summary:summarycal}
end tell
end tell
end tell
tell application "Finder"
get ((ThePath as text) & JobNumName) as alias
set the label index of the result to 2 -- 2 = red
end tell
Mac Pro (Mid 2010), Mac OS X (10.7.2)