I’m updating an old script I found with lots of deprecated info for variables. Trying to convert all of them to corresponding “System Events” properties, I stumbled when trying to extract an item’s container from its System Events properties.
This is still working in 10.11.3:
tell application "Finder"
set mySelection to selection as alias list
set itemContainer to container of item 1 of mySelection as text
end tell
return itemContainer --> "HD-1:Users:username:Desktop:" --> OK
But this current “System Events” container property fails to return the container cleanly:
tell application "Finder" to set mySelection to selection as alias list
tell application "System Events"
set itemContainer to container of item 1 of mySelection
return itemContainer
--> folder "HD-1:Users:usernames:Desktop:" of application "System Events"
-- The container path is there but not alone. What is the meaning of that?
-- Can it be extracted?
end tell
Although the container property is there on the first line of the property list,
the extraction fails the same way, surrounded by artefacts.
tell application "Finder" to set mySelection to selection as alias list
tell application "System Events"
set itemProperties to get properties of item 1 of mySelection
return itemProperties
--> {short version:"1.0", container:folder "HD-1:Users:usernames:Desktop:" of application "System Events", path:"HD-1:Users:usernames:Desktop:Scratch.scptd:", file type:missing value, volume:"HD-1", physical size:missing value, URL:"file:///Users/username/Desktop/Scratch.scptd/", id:"Scratch.scptd,-100,1267154"...}
set itemContainer to container of itemProperties
return itemContainer
--> folder "HD-1:Users:chris:Desktop:aaa:" of application "System Events"
end tell
Failing that, I did it this way:
tell application "Finder" to set mySelection to selection as alias list
tell application "System Events"
set itemPath to item 1 of mySelection as text
set itemName to name of item 1 of mySelection as text
-- Done with text manipulation:
set itemContainer to items 1 through (-2 - (length of itemName)) of itemPath as text
return itemContainer --> "HD-1:Users:username:Desktop:" --> OK
end tell
Please, can somebody explain why extracting the container from the “System Events” properties list fails. Is this a bug?
What am I missing?