Thanks but always no luck.
set brokenAliases to do shell script "/Users/admin/bin/AliasPath -bo"
set fileDescriptor to open for access ((path to desktop as text) & "FinderBrokenAliases.txt") with write permission
write brokenAliases to fileDescriptor
close access fileDescriptor
fails with the error :
error "2017-07-27 13:53:56.804 AliasPath[881:727082] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff837a057b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fff989f91da objc_exception_throw + 48
2 CoreFoundation 0x00007fff8381dc55 +[NSException raise:format:] + 197
3 Foundation 0x00007fff85158e8a -[NSURL(NSURL) initFileURLWithPath:] + 131
4 Foundation 0x00007fff85158df1 +[NSURL(NSURL) fileURLWithPath:] + 45
5 AliasPath 0x00000001089bd17e __main_block_invoke + 894
6 AliasPath 0x00000001089bc89c -[SpotlightSearch queryFinishedGathering:] + 1196
7 CoreFoundation 0x00007fff8372d54c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
8 CoreFoundation 0x00007fff8372d44b _CFXRegistrationPost + 427
9 CoreFoundation 0x00007fff8372d1b2 ___CFXNotificationPost_block_invoke + 50
10 CoreFoundation 0x00007fff836eb782 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 2018
11 CoreFoundation 0x00007fff836ea76b _CFXNotificationPost + 667
12 Foundation 0x00007fff8512c677 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
13 Foundation 0x00007fff852b4022 -[NSMetadataQuery _noteNote4:] + 158
14 CoreFoundation 0x00007fff8372d54c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
15 CoreFoundation 0x00007fff8372d44b _CFXRegistrationPost + 427
16 CoreFoundation 0x00007fff8372d1b2 ___CFXNotificationPost_block_invoke + 50
17 CoreFoundation 0x00007fff836eb782 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 2018
18 CoreFoundation 0x00007fff836ea76b _CFXNotificationPost + 667
19 CoreFoundation 0x00007fff837809f1 CFNotificationCenterPostNotificationWithOptions + 113
20 Metadata 0x00007fff84a8f5ad _postQueryNotification + 223
21 Metadata 0x00007fff84a5af77 ___pushNotification_block_invoke + 60
22 CoreFoundation 0x00007fff8373722c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
23 CoreFoundation 0x00007fff837183c4 __CFRunLoopDoBlocks + 356
24 CoreFoundation 0x00007fff83717f06 __CFRunLoopRun + 1894
25 CoreFoundation 0x00007fff83717544 CFRunLoopRunSpecific + 420
26 CoreFoundation 0x00007fff83756d31 CFRunLoopRun + 97
27 AliasPath 0x00000001089bcdbc main + 700
28 libdyld.dylib 0x00007fff992da235 start + 1
29 ??? 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException" number 1006
If you need extraneous details, you may ask directly thru my personal mailbox.
On my side I have a version doing the job but using GUIscripting. With 432 path returned by mdfind the entire process took 347 seconds.
set startTime to current date
tell application "Finder"
(*
set theWindows to every window
repeat with awindow in theWindows
# Close every info window once so we will not have to do it in the handler
if class of awindow is information window then close awindow
end repeat
*)
close every window
end tell
set l to paragraphs of (do shell script "mdfind \"kMDItemKind == 'Alias'\"")
set y to ""
set n to ""
set pass to 0
repeat with e in l
set pass to pass + 1
set p to POSIX file e
try
tell application "Finder"
try
set a to p as alias
on error
# Retry after adding return at end of the path
set e to e & return
tell me to set p to POSIX file e
set a to p as alias
end try
set theOriginal to my getOriginal(e) # here e is a POSIX path
if original item of a exists then
--set theOriginal to my getOriginal(e) # here e is a POSIX path
set y to y & e & tab & theOriginal & linefeed # Add path2alias & path2original in y
else
-- set theOriginal to my getOriginal(e) # here e is a POSIX path
set n to n & e & tab & theOriginal & linefeed # Add path2alias & path2original in n
log "***try"
end if
end tell
on error
set n to n & e & tab & "***error" & linefeed # Here, I get that with aliases appearing as greyed in the Finder window
--log "***error"
end try
--if pass = 50 then exit repeat # active only during tests
end repeat
# Save the list of broken aliases
set f to open for access (path to desktop as text) & "FinderBrokenAliasesXXX.txt" with write permission
write n as text to f
close access f
# Save the list of correct aliases
set f to open for access (path to desktop as text) & "FinderCorrectAliasesXXX.txt" with write permission
write y as text to f
close access f
set itsDuration to (current date) - startTime
tell application (path to frontmost application as string) to display dialog "It tooks : " & itsDuration & " seconds"
on getOriginal(brokenAliasPOSIXPath)
set aFile to POSIX file brokenAliasPOSIXPath
tell application "Finder"
select aFile # open the window of the folder containing the alias
set aFile to aFile as text
repeat 10 times
if ((get selection) as text) = aFile then exit repeat # Wait for the window containing the file
delay 0.2
end repeat
end tell # Finder
tell application "System Events" to tell process "Finder"
set frontmost to true
keystroke "i" using {command down} # Ask for Info window
tell application "Finder"
repeat 10 times # Wait for the new info window
delay 0.2
if (class of window 1) is information window then exit repeat
end repeat
end tell # Finder
tell window 1
--class of UI elements --> {scroll area, button, button, button, image, static text}
tell scroll area 1
--class of UI elements --> {image, static text, static text, static text, static text, scroll area, UI element, static text, static text, static text, static text, static text, static text, static text, static text, static text, static text, static text, static text, static text, static text, button, checkbox, UI element, static text, static text, UI element, static text, text field, checkbox, UI element, static text, UI element, static text, UI element, static text, static text, scroll area, button, button, menu button, checkbox}
set theTexts to value of static texts
repeat with i from 1 to count theTexts
if theTexts's item i starts with "/" then
set theOriginal to theTexts's item i
log "got the original : " & theOriginal
exit repeat
end if
end repeat
end tell
-- subrole of buttons --> {"AXCloseButton", "AXZoomButton", "AXMinimizeButton"}
click button 1 # Close the Infos window
end tell # window 1
end tell # System Events …
tell application "Finder" to close window 1
if i = (count theTexts) then set theOriginal to "** no original available **" # The window doesn't display an original, build a fake string
return theOriginal --> "/Important/Téléchargements/ téléchargés pour Leopard/maj_Apple"
end getOriginal
#=====
This time I am satisfied because it no longer rely upon a localized string and it treat the “annoying” pathnames (using brute force).
Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) jeudi 27 juillet 2017 13:58:44