Alias via GetOpenFolderItem

How can I get through a Dialog window the path of a file which is an Alias ? In such a case, GetOpenFolderItem gives me the file that is pointed to by the Alias, not the Alias itself.

You could use our OpenDialogMBS class or one of the others which allow you to select aliases.

Check out the help system for FolderItem.Item and FolderItem.TrueItem

FolderItem can be used ONLY for a folder, not a file (which is my case)

@Daniel: folderitem can be both folder and file.

It can represent files, folders, or volumes. As for your question about aliases and GetOpenFolderItem, have you filed a feature request?

You really need to read the manual before making wrong statements :wink:

I actually just happen to have the similar problem. It works correctly on the Mac, but not on Windows (XP,7,8) When trying to open an alias folder the results is a folder with no content and the attribute “alias” is set to false.
I also found a bug in the FolderItem where I made a workaround but may be it could easily resolved by XOJO: When a folder path contains a double folder separator ("//" or “::”) the program crashes. Probably because of the resulting empty folder name.

That looks terribly much like an invalid path. Makes sense it crashes. Do you test folderItem.Exists after pointing to such oddities ?

sure
Also folderitem.Exists sometimes under Windows does not work at all
Besides the app usually does not crash because of a wrong path, but sets an error, any other wrong path will issue such an error but the above one crashed the app which is a major bug I think

I don’t know if the feature request has been filed, but still there :
When I select an Alias with OpenDialog then it returns the True items.
If I do the same in AppleScript with “choose file” it returns the Alias.

[quote=199359:@Thomas ROBISSON]I don’t know if the feature request has been filed, but still there :
When I select an Alias with OpenDialog then it returns the True items.
If I do the same in AppleScript with “choose file” it returns the Alias.[/quote]

Usually, users will expect to get the target and not the alias. Yet, if AppleScript returns the alias instead of the target, that could be the solution for people who want to pick the alias itself. It should be possible to place the AppleScript in the project and return the path to the alias.

I just looked a bit further into TrueItem, and came up with what could be an alias picker :

dim contain as folderitem = specialfolder.desktop for i as integer = 1 to contain.count if contain.TrueItem(i).Alias then PopupMenu1.AddRow(contain.TrueItem(i).name+" points to : "+contain.Item(i).shellpath) end if next

I still fail to see the exact use for such a thing, though…

I see that if I make the Alias manualy in the Finder, it works, I can’t get the TrueItem (alias) from AppleScript and not the Target.
If I create the Alias from AppleScriptit works too (as it’s the same as if I do it manualy).

If I create the Alias fromshell using "ln - s " (command given by Michel in another thread) it doesn’t work.

Nothing to do with that, but I’m trying to learn some shell command, and as a sily guy I tried “rm”. I wanted to empty my Trash using ""rm -rf " + MyTrash.ShellPath + “/"" but I forgot the "”. it erased all my hard-drive ! :’’’’( .

[quote=199378:@Thomas ROBISSON]I see that if I make the Alias manualy in the Finder, it works, I can’t get the TrueItem (alias) from AppleScript and not the Target.
If I create the Alias from AppleScriptit works too (as it’s the same as if I do it manualy).

If I create the Alias fromshell using "ln - s " (command given by Michel in another thread) it doesn’t work.

Nothing to do with that, but I’m trying to learn some shell command, and as a sily guy I tried “rm”. I wanted to empty my Trash using ""rm -rf " + MyTrash.ShellPath + “/"" but I forgot the "”. it erased all my hard-drive ! :’’’’( .[/quote]

Ah, I see. Ln -s is not an Alias, it is a Unix symbolic link. That is the reason why you cannot get its location.

Sorry to read about the wild rm !

Thank you Michel. I just want to be able to choose an Alias in order to delete it when the user choose it.

Here is a snippet that does not return the target, but the alias itself :

[code] dim f as FolderItem = GetOpenFolderItem(“special/any”)

if f <> nil and f.exists then
dim contain as folderitem = specialfolder.desktop
for i as integer = 1 to contain.count
if contain.TrueItem(i).Alias then
if contain.Item(i).shellpath = f.shellpath then
f = contain.TrueItem(i)
exit
end if
end if
next
end if

Msgbox f.shellpath[/code]

Note that this will also see the true path of symbolic links.

Hi, thank you. But it works if the Alias is in Desktop. If I want an alias in a folder somewhere else?
In other case(don’t find alias) you’re script return the first line : f as FolderItem = GetOpenFolderItem(“special/any”).

But don’t worry, I use my Applescript when I want a TrueItem.

And I did a synchronisation yesterday evening, as each time I spend time on my computer. Then I loose one day work.
All my documents are on a second partition, this is this partition which was erased, not the partition with the system etc.

What do you mean ? The second snippet uses the standard open file. You can navigate to any part of the file system.

Oops. I see now Contain is desktop. Sorry about that.