i can not access the alias’ “original item” property of 100+ of my aliases
they do target exisiting files which i originally stored on external harddrives
which do not exist anymore.
is there any way to extract the original target path from the alias or alias’ info panel
of the broken alias’ (eventhough the path are not targeting any existing drive)
and use them with apple script ?
as an alias file is a real-time pointer to a file reference in the file system, the property original item is empty
if the target file has been deleted or the target volume is temporarily not available
i was afraid to hear that -
is there any opportunity to access this poroperty though -
… any shell or other scripts that may solve the problem
… any system file which hosts the the source for the info panel’s link* ?
i wonder why the original links are still displayed eventhough their property
is not accessable anymore.
@ herfmarc: the Finder is not needed, but the path to the alias file must be valid
The explanation why the property original file in the Finder is empty but the path is displayed in the info window:
The alias information is stored in a resource of the alias file.
While accessing the alias file with AppleScript the Finder calls a routine “ResolveAlias”,
which determines the original file. This fails due to the known reasons, if the original file is not available.
The info window reads the information directly from the resource and displays the target path.
thanks, again - but (i blame this on my total lack of applescript skills)
there’s still something that i do wrong
set TheBrokenAlias to “Ohne Titel:Users:my_mac:Desktop:recover missing item alias”
load resource 0 type “alis” from file TheBrokenAlias
let me compile the first line
whereas the 2nd is still refused by the messages
“syntax error - Expected end of line, etc. but found identifier.”
i tried it several times,
… checking the path (+ letting applescript doing it using the “as text” clause)
… using OSX10.5.6 and osx10.6.4
… with & without the "tell application “Finder” … code
am sure that i leave off a tiny bit that keeps it from working -
but which ?
maybe there is a invisible character somewhere, try this,
select an item in the Finder and run the script.
it displays the path of the selected item.
tell application "Finder" to set TheBrokenAlias to item 1 of (get selection) as text
display dialog "alias file path: " & TheBrokenAlias
(load resource 0 type "alis" from file TheBrokenAlias)
just tried it with OSX 10.6.4 and received error messages again
(guess the ScriptingAddition might not be supported or something went wrong when i installed it)
I found annother (far less elegant way) using the info window
(-- i had “Satimage.osax” + “gui scripting” ScriptingAdditions installed - don´t know though if they were necessary)
but
this does not seem to work with OSX 10.5.8 …
will post it since it might be useful for someone who is struggling with the same issue
thanks, again, for all the helpful replies
tell application "Finder"
--
set source_folder to choose folder -- select, get and check files from pop-up menu's folder choice
set theSelection to (entire contents of folder source_folder)
--
repeat with aFile in theSelection -- loop through the selected files
--
-- check if alias
if class of aFile is alias file then -- choose and proceed with all aliases
-- get entries from info window of selected file 2 --- the alias# information window properties
--
-- opens info window
open information window of file (aFile as text)
--
set theWindowName to (name of aFile as text) & " info" --- variable for name of info window
--
tell application "System Events"
tell process "Finder"
-- set New original item for new alias - the alias' target file/folder's path
--
--
return value of static text 19 of scroll area 1 of window theWindowName -- the link to the referenced file
-- set theFile to value of static text 19 of scroll area 1 of window theWindowName -- the link to the referenced file as variable
--
-- e.g. ... - set theFile to "/Users/my_mac/Desktop/FoldrX2/FoldrX/FileX" -- the link to the referenced file
--
end tell -- tell process "Finder"
end tell -- application "System Events"
--
close information window of file (aFile as text) -- closes information window
--
end if -- if class of aFile is alias file then
--
--
end repeat --aFile in theSelection -- loop through the selected files
end tell
I just tried this on Yosemite, and unfortunately it didn’t work (no big surprise).
I repurposed some code Shane wrote on the Applescript Users List to do the same thing.
-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/08/31 11:45
# dMod: 2015/08/31 12:06
# Appl: Finder
# Task: Get Original Item Path from Selected Alias File in Finder.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Finder, @Alias, @Original_Item
# Test: OSX 10.10.5
-------------------------------------------------------------------------------------------
use AppleScript version "2.3.1"
use framework "Foundation"
tell application "Finder"
set finderSelectionList to selection as alias list
if finderSelectionList ≠{} then
set theAliasFile to item 1 of finderSelectionList
if kind of theAliasFile ≠"Alias" then error "The selected file is NOT an alias file!"
else
error "No selection in the Finder!"
end if
end tell
set posixFilePath to POSIX path of theAliasFile
set theOriginalItem to my nameOfOriginalFileForAlias:posixFilePath
-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on nameOfOriginalFileForAlias:posixPath
tell current application's class "NSURL"
# Make URL
set anNSURL to its fileURLWithPath:posixPath
# Load data from alias file
set theData to its bookmarkDataWithContentsOfURL:anNSURL |error|:(missing value)
# Get value as dictionary from data
set theResult to its resourceValuesForKeys:{current application's NSURLPathKey} fromBookmarkData:theData
end tell
# Extract original item and coerce to text
return (theResult's objectForKey:(current application's NSURLPathKey)) as text
end nameOfOriginalFileForAlias:
-------------------------------------------------------------------------------------------