Hi!
I need to get the original item for aliases. The problem is I cannot ask the Finder, because I have to do this during a drop-operation in an AppleScriptStudio project, and if I do so, the Finder hangs for about 20 seconds.
I don’t know if this will work but the theory is sound :). You can create an Objective-C class for your ASStudio project called AliasResolver. In that class you would define a class method that you would call in your script. But first, you will need the methods to resolve the alias. I found the following from karelia.com:
Put these method implementations in the AliasResolver.m file after the “@implementation AliasResolver” and before the “@end”. In the AliasResolver.h file you need to declare the method prototypes before the “@end” and after the closing brace “}”. The prototypes would look like:
set originalPath to (call method "originalItemPathForAlias:" of class "AliasResolver" with parameter (POSIX path of aliasFilePath))
I haven’t done something like this in ASStudio in a while and I don’t have any of my projects that do this here at work, so I can’t verify and say this will work with certainty, but this is the basic idea. And I have tested the Obj-C code and it works fine.
I am missing something here, and I would really like to know what it is. Why can you not simply do this?
set a to choose file
-->alias "Pilate:Users:bhuricomepeerayos:Desktop:application2.doc"
set b to POSIX file (a's POSIX path)
b
-->file "Pilate:Users:bhuricomepeerayos:Desktop:application2.doc"
He’s looking to resolve aliases not aliases :). The kind you make when you Command-Option-drag a file in the Finder. And he wants to do it without a call to the Finder. I was surprised that System Events doesn’t have anything to handle this. But, then again, I might’ve missed something in its dictionary. And though Standard Additions can tell you if an item is an alias, it doesn’t appear to have the original item property. Hence my long and convoluted workaround.
I forgot to mention that I think the CoreServices frameworks need to be added to the project. This includes the CarbonCore framework which has the Alias.h file where the C functions used in the above Obj-C code is defined.
I can´t use the idle handler, because of the nasty bug that occurs when the idle handler fires during a delay. There is a thread about this here somewhere, and I know the alternatives for the delay statement, but they are not very useful for me.
thx anyway
My limited testing shows that something like this may work:
choose file with prompt "Choose an alias:" without invisibles
set theAlias to result
try
do shell script "/usr/bin/strings " & quoted form of ((POSIX path of theAlias) & "/rsrc") & " | /usr/bin/grep ':' | /usr/bin/colrm 1 1"
set theOriginal to (first paragraph of result) as alias
on error errMsg number errNum
display dialog "Error " & errNum & ":" & return & return & errMsg buttons {"Cancel"} default button 1 with icon caution
end try
Basically what you do is control the delay from the idle handler. Something like this:
property the_delay : 2
property will_delay : false
--
on idle
if will_delay then
-- do nothing
else
-- do whatever
end if
return the_delay
end idle
This is just to emphasize what you’re doing. From a separate script or threaded handler you adjust the property and the idle handler either delays or its routine.