Struggling a bit with @showif with evaluator and filepath

Goal: Basically my goal is to have an option appear in the right click context menu only when right clicking a symbolic link folder. Or at least a toolbar button that does the same.

My current approach has been to try and start with this evaluator logic to simply check if the resolved path of the selected file is the same as the regular unresolved path.

(I can't remember if filepath$ or filepath is the proper way to reference it in an evaluator but both seem to work):

@Output Resolved Path Is Same:   {=Resolve(filepath$,"js")==filepath$=}
@Output Resolved Path Is Same:   {=Resolve(filepath,"js")==filepath=}

And that logic does work, outputting true for regular files/folders, and false for shortcuts/symbolic links. At least when running it via clicking the button or hitting "Run" in the command editor.


Problem:

However I've been struggling to get it to work with @showif / @hideif. No matter what I try, it always seems to show an error in the log about filepath being an unknown value.

For example, if this is applied to a toolbar button:
@hideif:=Resolve(filepath,"js")==filepath

Then when the command editor is closed so Directory Opus is just in the usual usage context, the logs show:

11/4/2024 9:06 AM Evaluator: Error at line 1, position 9
Unknown value (6): filepath
Resolve(filepath,"js")==filepath

Same if using filepath$, though again not sure the difference:
@hideif:=Resolve(filepath$,"js")==filepath$

Unknown value (6): filepath$


Other Stuff I Tried:

I was able to have some success testing @showif / @hideif so that it only shows the button if a single folder is selected like this:
@showif:=((FileCount(true,"dirs:*") == 1) && (FileCount(true,"files:*") == 0))

However I guess FileCount() only applies to the file name and not the entire path so it wouldn't apply to my case.

I thought maybe I could assign filepath to a variable first like this as a test:

@evalalways:{currPath = filepath}
@hideif:=Resolve(currPath,"js")==currPath

But that ends up just saying currPath is unknown:

11/4/2024 9:33 AM Evaluator: Error at line 1, position 9
Unknown value (6): currPath
Resolve(currPath,"js")==currPath

And even if I just have it try to output the currPath evaluator variable when running it as a button press:
@Output {=currPath=}

It just outputs the evaluator preparse dummy file path:

C:\Evaluator-Preparse-Dummy-Filename.txt


Other approaches:

Since I already have a filter set in the preferences for identifying symlinks (which I use to color them in the lister) I was trying to figure out if it was possible to use filters with the evaluator somehow, but couldn't figure it out. If that's possible though I could start a separate thread that focuses on that question.

I don't think the $ has any meaning here. I am surprised it doesn't cause problems.

Yes, in this context you need to use selpath.

Evaluator Conditional Button Behavior [Directory Opus Manual]

1 Like

Ah selpath is indeed the key!

For future reference to anyone, my final code for the context menu entry is this, which I put on 'All Files and Folders' filetype:

@nofilenamequoting 
@showif:=((selitems == 1) && (Resolve(selpath,"j") != selpath))
Go "{=Resolve(filepath,"j")=}"

That ensures that it only shows if one thing is selected, and the resolved path is different from the apparent path.

Turns out the Go command will work with files too, not just directories -- if given a file path, it will take you to the resolved file's parent directory and select the file automatically without any additional logic needed. So you can put those same lines of code alternatively onto just "All Files" or "All Folders" if you want.

It could also be made to work with shortcuts by changing the "j" parameter in the Resolve() function to "js" to include shortcuts. (Though clicking the shortcut would take you to the same place anyway so that wouldn't matter I guess)