alias - original item - missing value ?

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 ?

i already wrote a script which allows to replace chunks of the path -
(http://macscripter.net/viewtopic.php?pid=134227#p134227)
i only need to access the path.

am desperate, googled for hours and tried to find an answer on this forum …
any help is highly appreciated

Hi,

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

Hi stefan,

thanks for your immediate reply.

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.

looks like i need to manually re-adjust it …

Hi, try this:

set TheBrokenAlias to "path:to:your:alias"
load resource 0 type "alis" from file TheBrokenAlias

nice weekend :slight_smile:

Hans

Hi Hans,

thanks a lot for the hint.

i tried that but received
“Expected end of line, etc. but found identifier.”

do i need to add something above or below

tell application “Finder”

set TheBrokenAlias to “Macintosh Hd:users:Me:Desktop:filename alias”
load resource 0 type “alis” from file TheBrokenAlias

end tell

?

best regards

@ Hans-Gerd: pretty clever solution :slight_smile:

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


thanks a lot, again -

i tried that and applescript told me :
" syntax error: Expected “,” but found identifier."
when compiling.


the first 2 lines work perfect
and aplescript rewards me displaying:

alias file path: Ohne Titel:Users:my_mac:Desktop:recover missing item alias:


i assume that this might relate to some security-or-whatever settings
or my version of script editor (2.2.1 and 2.3)

and this now when i was so close to finding a solution: darrrrn.

On my machine (10.5.8, Script Editor 2.2.1 and Script Debugger 4.5.6) it works flawlessly

must be something about my settings -
got to check it & will google if there are any known issues
&
will definitely send a post if i find an answer.

meanwhile:
thanks so much for your patience & hints,
i appreciate your support !

have a great evening
best regards

Hi @ all,

please excuse :confused:

you’ll need to install the satimage.osax Scripting Addition.

possibilities:
get, list, load and put resources

so, give it a second try …

… ahhhhhhh, thanks so much, hans: what a relief !

works great now & definitely solves my problem.
have a great sunday

… a million ‘thank you’s’
go out to stefan and hans !

just a brief add-on:

all worked perfect with my OSX 10.5.8

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

just for fun I wrote a Foundation Tool command line interface, which retrieves the original path of an alias file from the resource fork

You can download it here: AliasTargetPath,

Save it somewhere and call it from AppleScript with

do shell script "/path/to/AliasTargetPath /path/to/AliasFile"

it works in both 10.5 and 10.6

thanks - will definitely try this one …
have a great evening

best regards !

Hey Stefan,

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

-Chris


MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.10.5

Perhaps you could use Howard Oakley’s command line tool for aliases, alisma:

alisma -p aliasfile
which returns the path to the original item which is pointed to by the Alias at the path aliasfile.