When i try to migrate to OS 10.11 i have an error message “ “item 1 of {file “work HD:Folder:file_name.ai”} doesn’t understand the “path” message” in this handler
on btnInputFiles:sender # Objective-C as AppleScript
set my vectorFilePosixPaths to {} -- will contain vector POSIX paths
set my rasterFilePosixPaths to {} -- will contain raster POSIX paths
set thePanel to current application's NSOpenPanel's openPanel()
set startURL to current application's NSURL's fileURLWithPath:(POSIX path of (path to desktop))
tell thePanel
its setMessage:"Open file:"
its setAllowedFileTypes:vectorExtensionList
its setTitle:"My Open Title"
its setShowsHiddenFiles:false
its setTreatsFilePackagesAsDirectories:false
its setDirectoryURL:startURL
its setCanChooseFiles:true
its setCanChooseDirectories:true
its setAllowsMultipleSelection:true
set returnCode to its runModal() as integer
end tell
set returnCode to returnCode as integer
if returnCode = (current application's NSFileHandlingPanelOKButton) as integer then
set theURLs to thePanel's URLs() as list
repeat with i from 1 to count of theURLs
try #1
set thePosixPath to (item i of theURLs)'s |path|() -- here is an error
--set thePosixPath to (item i of theURLs)
on error the error_message number the error_number
set my alertHeader to the "#1. Error in \"btnInputFiles\" number: " & error_number
set my alertBody to the error_message as text
its showAlertAsSheet_(alertHeader, alertBody)
end try
log thePosixPath
-- and if you want an HFS path:
try #2
set hfsPath to (((thePosixPath as text) as POSIX file) as text)
on error the error_message number the error_number
set my alertHeader to the "#2. Error in \"btnInputFiles\" number: " & error_number
set my alertBody to the error_message as text
its showAlertAsSheet_(alertHeader, alertBody)
end try
--log hfsPath
(its collectFromItem:thePosixPath vectorFiles:vectorFilePosixPaths rasterFiles:rasterFilePosixPaths)
if (thePanel's respondsToSelector:"tagNames") as boolean then
set theTags to thePanel's tagNames()
if theTags = missing value then
log "No tags"
else
log theTags
end if
end if
end repeat
else
set my chkWhatYouDo to 0 as integer -- ÑтатуÑÑ‹ чекбокÑов выбора файлов OFF
log "Cancel pressed"
end if
my sortingAndVerify_()
end btnInputFiles:
don’t coerce URLs() to list, because in 10.11 the conversion to an AppleScript list seems to bridge the NSURL items implicitly to AppleScript file specifier and file doesn’t respond to path
Try this
set theURLs to thePanel's URLs()
repeat with anURL in theURLs
set thePosixPath to anURL's |path|()
.
thePosixPath is a Cocoa NSString object, If you need an AppleScript string write
You need to check the release notes. One of the changes in 10.11 is that files and NSURLs are now bridged. So in your script, URLs() returns an array of NSURLs, and when you convert it to a list, the URLs within it are converted to files.
You need to keep it an array and loop through the array like this:
set theURLs to thePanel's URLs()
repeat with i from 1 to theURLs's |count|()
try #1
set oneURL to theURLs's objectAtIndex:(i-1)
set thePosixPath to oneURL's |path|() -- here is an error
That’s nice – I’m a bit surprised it works. I would have assumed that “repeat with anURL in…” would have forced conversion of the array to a list, resulting in the same problem with the list’s items, but it looks like sticking to references somehow avoids coercion of the list’s contents.
In case start loop with “repeat with i from 1 to theURLs’s |count|()”
{file “Work HD:Work:Sberbank:SB_FRK_Pensioners_Gifts:5_Layouts:Angarsk_SB_PGift_Vremya_250x180.ai”} doesn’t understand the “count” message.
In case start loop with “repeat with i from 1 to count of theURLs”
doesn’t understand the “objectAtIndex” message
It’s also a bit faster. The only downside is that it can cause stability problems when run within an editor in 10.10 – logging references to pointers provokes a crashing AS over-release bug.
I just take a project from Shane’s book (“Open and Save”, chapter 17) open in Xcode and got a same errors.
Thanks, Shane, thanks Stefan
i think its work.
set theURLs to thePanel's URLs()
repeat with anURL in theURLs
try #1
set thePosixPath to (anURL's |path|()) as text
log (anURL's |path|()) as text
on error the error_message number the error_number
set my alertHeader to the "#1. Error in \"btnInputFiles\" number: " & error_number
set my alertBody to the error_message as text
its showAlertAsSheet_(alertHeader, alertBody)
end try
log thePosixPath
-- and if you want an HFS path:
try #2
set hfsPath to (((thePosixPath as text) as POSIX file) as text)
on error the error_message number the error_number
set my alertHeader to the "#2. Error in \"btnInputFiles\" number: " & error_number
set my alertBody to the error_message as text
its showAlertAsSheet_(alertHeader, alertBody)
end try
--log hfsPath
(its collectFromItem:thePosixPath vectorFiles:vectorFilePosixPaths rasterFiles:rasterFilePosixPaths)
if (thePanel's respondsToSelector:"tagNames") as boolean then
set theTags to thePanel's tagNames()
if theTags = missing value then
log "No tags"
else
log theTags
end if
end if
end repeat
It’s more a Script Editor/Script Debugger issue. Take this code:
use framework "Foundation"
set x to current application's NSArray's arrayWithArray:{"One", "Two", "Three", "Four", "Five", "Six"}
repeat with aval in x
set y to aval
log y
end repeat
If you run it 3-4 times in Script Editor with Events and Replies showing, under 10.10 it will crash SE. It’s fine under 10.11. The issue affects Script Debugger even more, because it is continually producing text representations of values for its Variables table. (And ASObjC Explorer works around the issue altogether.)
I was curious to see how much affect using item i of would have. So I compared these two snippets:
-- allFiles is a big array of URLs, the result of enumerating /Applications recursively
repeat with i from 1 to allFiles's |count|()
set aPath to ((item i of allFiles)'s |path|())
end repeat
And:
-- allFiles is a big array of URLs, the result of enumerating /Applications recursively
repeat with anNSURL in allFiles
set aPath to (anNSURL's |path|())
end repeat
And even:
-- allFiles is a big array of URLs, the result of enumerating /Applications recursively
repeat with i from 1 to count of items of allFiles
set aPath to ((item i of allFiles)'s |path|())
end repeat
To my (further) surprise, there was next-to-nothing in it.