it scans the frontmost folder in the Finder and saves an alias reference of every file into a property. (the folder contains a mixture of image and AAE files from an iPhone.
I then change the names of the image files in the folder using A Better Finder Rename.
I then run the applet again. this time, the applet compares the list it has saved in the property, with the files in the folder. it notes any name changes and applies those name changes to the matching AAE files.
this worked for a long time, but not any longer. now when the applet runs through the list of aliases in the property, it can no longer locate the target of the alias and returns a -1,728 error. it’s as if the applet is saving a list of strings instead of a list of aliases.
has anyone run into this problem?
-- first pass. scan folder and save aliases to applet property
tell application "Finder"
copy window 1's target to imageFolder
copy (every item of imageFolder) as alias list to imageFiles
end tell
-- second pass, after image files have been renamed. scan folder and compare names of aliases.
tell application "Finder"
set imageFilesNames_new to {}
repeat with f from 1 to imageFiles's length
set theAlias to imageFiles's item f
-- -1,728 error in the next line for files whose names have changed.
copy name of theAlias to end of imageFilesNames_new
end repeat
end tell
LOL. “a long time”… possibly several months, maybe even a year.
I tried saving the list of file references as «class furl» instead of alias, but the error still continues.
I don’t recompile between the two runs.
here is a really simple test script to demonstrate the problem.
property theFile : ""
on run
if theFile is "" then
-- first pass.
tell application "Finder"
copy window 1's target to imageFolder
copy (first item of imageFolder) as alias to theFile
end tell
else
-- second pass.
tell application "Finder" to ¬
copy name of theFile to x
end if
end run
open a folder in the Finder.
run the script once (in your script editor).
note the file that the script recorded, and change its name in the Finder.
run the script again.
-> error -1,728
This version of your example works for me on Catalina:
property theFile : ""
on run
if theFile is "" then
-- first pass.
tell application "Finder"
copy Finder window 1's target to imageFolder
copy (first item of imageFolder) as alias to theFile
end tell
else
-- second pass.
tell application "Finder" to ¬
copy name of theFile to x
end if
end run
Yes, AFPS volumes do no support alias tracking. Alias files are now actually bookmarks under the hood.
You could re-write your code using ASObjC and bookmarks. It’s a little complicated because they’re data, so you’d probably need to do something like Base64 encode them and store the resulting strings.
Something like this:
use AppleScript version "2.5" -- macOS 10.11 or later
use framework "Foundation"
use scripting additions
property imageFilesNames_new : {}
property imageFiles : {}
-- first pass. scan folder and save aliases to applet property
tell application "Finder"
copy window 1's target to imageFolder
set theFiles to (every item of imageFolder) as alias list
end tell
set theFiles to current application's NSArray's arrayWithArray:theFiles -- converts to URLs
set my imageFiles to {} -- reset property
repeat with aFile in theFiles
set theData to (aFile's bookmarkDataWithOptions:0 includingResourceValuesForKeys:{} relativeToURL:(missing value) |error|:(missing value))
set end of imageFiles to (theData's base64EncodedStringWithOptions:0) as text
end repeat
-- second pass, after image files have been renamed. scan folder and compare names of aliases.
set my imageFilesNames_new to {} -- reset property
repeat with aBookmark in imageFiles
set theData to (current application's NSData's alloc()'s initWithBase64EncodedString:aBookmark options:0)
set theURL to (current application's NSURL's URLByResolvingBookmarkData:theData options:0 relativeToURL:(missing value) bookmarkDataIsStale:(missing value) |error|:(missing value))
set end of imageFilesNames_new to theURL's lastPathComponent() as text
end repeat
But it gets even more complicated, because using ASObjC means your properties won’t persist. And honestly, now’s a good time to think about moving away from properties as a method of persistence anyway. And if you do, you can skip the Base64 stuff.