To add to the list of very annoying Finder bugs, here is a new one - to me at least:
set aFile to choose file default location path to desktop folder
tell application "Finder"
set name of aFile to "XXX"
log aFile
update aFile
end tell
This is the Finder’s reply:
set name of alias "Mojave:Users:didoda:Desktop:yyy" to "XXX"
--> "XXX"
update alias "/Users/didoda/Desktop/yyy"
Error: File not found (fnfErr:-43)
My point is not (so much) that since the file is referenced as an alias, the Finder should be aware of its own previous name change (which sometimes it does, sometimes not), but that it converts the colon separated HFS path to a slash separated posix path for use in an alias reference!? (I use update
here only since it seemed to give consistent results, at least after the file rename, some other commands show this bug inconsistently, e. g. the Finder’s move, copy or choose file)
On top of it, at least on my system, this
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
alias "Mojave:Users:didoda:Desktop:XXX"
alias "/Users/didoda/Desktop/XXX"
sometimes even works, but as soon as you comment out the use framework line the second alias reference causes an error. This seems all very very volatile.
Has anybody seen this?
Does anybody know a workaround? Except using ASObjC or Shane’s FileManagerLib to avoid the whole Finder mess, of course.
On a side note, I wonder why using do shell script "cp -a ...."
or the like does not seem to be popular among scripters.
Thanks a lot for any input!
P.S. Just checked: this bug can be observed in both SD 8.0.6 and Script Editor.
tell application "Script Editor"
choose file default location alias "Mojave:Users:didado:Desktop:"
end tell
tell application "Finder"
set name of alias "Mojave:Users:didado:Desktop:yyy" to "xxx"
(*alias /Users/didado/Desktop/yyy*)
update alias "/Users/didado/Desktop/yyy"
Ergebnis:
error "„Finder“ hat einen Fehler erhalten: Die Datei „some object“ wurde nicht gefunden." number -43
[Sorry for the many edits…]