Monday, December 18, 2017

#1 2015-10-08 05:06:39 am

ilexxey
Member
From:: Moscow
Registered: 2012-08-02
Posts: 94
Website

El Capitan – doesn't understand the "path" message

Hi, peoples

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

Applescript:


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:

Last edited by ilexxey (2015-10-08 05:10:21 am)


Regards, Alex

Offline

 

#2 2015-10-08 05:28:43 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: El Capitan – doesn't understand the "path" message

Hi,

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

Applescript:

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

Applescript:

set thePosixPath to (anURL's |path|()) as text

Last edited by StefanK (2015-10-08 05:34:48 am)


regards

Stefan

Offline

 

#3 2015-10-08 05:35:04 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: El Capitan – doesn't understand the "path" message

ilexxey wrote:

Applescript:


           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


Alex,

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:

Applescript:


           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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#4 2015-10-08 05:48:08 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: El Capitan – doesn't understand the "path" message

StefanK wrote:

Applescript:

set theURLs to thePanel's URLs()
repeat with anURL in theURLs
…


Stefan,

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#5 2015-10-08 05:52:06 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: El Capitan – doesn't understand the "path" message

Shane, I was surprised too when I tested the syntax … smile


regards

Stefan

Offline

 

#6 2015-10-08 06:10:21 am

ilexxey
Member
From:: Moscow
Registered: 2012-08-02
Posts: 94
Website

Re: El Capitan – doesn't understand the "path" message

Hi Shane, hi Stefan smile


I have different errors:

1. 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.

2. In case start loop with "repeat with i from 1 to count of theURLs"
doesn’t understand the “objectAtIndex” message

roll


Regards, Alex

Offline

 

#7 2015-10-08 06:14:14 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: El Capitan – doesn't understand the "path" message

ilexxey wrote:

1. 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 this line:

Applescript:

set theURLs to thePanel's URLs() as list

delete the "as list".


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#8 2015-10-08 06:39:50 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: El Capitan – doesn't understand the "path" message

StefanK wrote:

Shane, I was surprised too when I tested the syntax …


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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#9 2015-10-08 06:45:59 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: El Capitan – doesn't understand the "path" message

Shane Stanley wrote:

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 ran the code in Xcode a few dozen times using this logging line

Applescript:

log (anURL's |path|()) as text

without any problems


regards

Stefan

Offline

 

#10 2015-10-08 06:59:23 am

ilexxey
Member
From:: Moscow
Registered: 2012-08-02
Posts: 94
Website

Re: El Capitan – doesn't understand the "path" message

I didn't nothing difficult smile

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.


Applescript:


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

Last edited by ilexxey (2015-10-08 07:07:38 am)


Regards, Alex

Offline

 

#11 2015-10-08 07:07:42 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: El Capitan – doesn't understand the "path" message

Stefan,

It's more a Script Editor/Script Debugger issue. Take this code:

Applescript:

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.)

Last edited by Shane Stanley (2015-10-08 07:08:33 am)


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#12 2015-10-08 07:13:00 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: El Capitan – doesn't understand the "path" message

ilexxey wrote:

I just take a project from Shane's book ("Open and Save", chapter 17) open in Xcode and got a same errors.


It's ironic -- my wish finally came true, and it broke my scripts smile


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#13 2015-10-08 10:04:47 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: El Capitan – doesn't understand the "path" message

Stefan,

I was curious to see how much affect using item i of would have. So I compared these two snippets:

Applescript:

   -- 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:

Applescript:

   -- 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:

Applescript:

   -- 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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)