Delete Alias Using Evaluator

Directory Opus: 13.20.4 Build 9412 x64
OS: 10.0 Pro 22H2 Build 19045.5247
Hardware: Intel Core i7-1065G7 • 16GB DDR4 RAM

Trying to delete an alias by getting the alias name using Resolve():

Favorites ALIAS=delete NAME=Resolve(source, "aef")

Please help me understand how to make this work, if possible.

Also, I think you can run things using the pure Evaluator, so that approach might be better since you can first check whether the alias actually exists.

To clarify, I already know the alias exists based on the button I am using that leverages Evaluator to display the alias as a tooltip:

<?xml version="1.0"?>
<button 3dborders="no" backcol="none" display="label" label_pos="right" textcol="none" type="menu_button">
	<label>Path</label>
	<tip>=DisplayName(source) + &quot;\n\nAlias: &quot; + Resolve(source, &quot;aef&quot;) + &quot;\n\nDepth: &quot; + Count(source) + &quot;  ♦  Folders: &quot; + FileCount(&quot;dirs:*&quot;) + &quot;  ♦  Files: &quot; + FileCount(&quot;files:*&quot;) + &quot;\n\n - Tab List&quot;</tip>
	<icon1>#newbuttonmenu</icon1>
	<function type="normal">
		<instruction>@label:PathType(source) == &quot;coll&quot; ? &quot;Search Results&quot; : (Count(source)&gt;2 ? Root(source) + &quot;\..\&quot; + FilePart(source) : source)</instruction>
		<instruction>@keydown:none</instruction>
		<instruction>Prefs PAGE=aliases </instruction>
		<instruction>@keydown:ctrl </instruction>
		<instruction>Favorites ALIAS=set NAME=&quot;{dlgstringS|Create New Alias:|{file|noext}}&quot; PATH {sourcepath} </instruction>
		<instruction>@keydown:shift</instruction>
		<instruction>Favorites ALIAS=delete NAME=Resolve({=source=}, &quot;aef&quot;)</instruction>
	</function>
	<button backcol="none" display="label" field_type="label" size="full" textcol="none">
		<label>LEFT  |  TOP Tab List</label>
		<icon1>#label</icon1>
		<function type="normal">
			<instruction>Set LABEL</instruction>
		</function>
	</button>
	<button backcol="none" display="label" separate="yes" textcol="none">
		<label>Tablist Left</label>
		<icon1>#newcommand</icon1>
		<function type="normal">
			<instruction>Go TABLIST=namesonly OPENINLEFT</instruction>
		</function>
	</button>
	<button backcol="none" display="label" field_type="label" size="full" textcol="none">
		<label>RIGHT  |  BOTTOM Tab List</label>
		<icon1>#label</icon1>
		<function type="normal">
			<instruction>Set LABEL</instruction>
		</function>
	</button>
	<button backcol="none" display="label" textcol="none">
		<label>Tablist Right</label>
		<icon1>#newcommand</icon1>
		<function type="normal">
			<instruction>Go TABLIST=namesonly OPENINRIGHT</instruction>
		</function>
	</button>
</button>

Not tested, but this should work in an Evaluator Function type button.
Note that Resolve is not fully documented, so I just trust you and use the flags you provided.

alias = Resolve(source,"aef");
//Output(alias);
if (!alias) return;
id = Dialog("r","Really remove """ + alias + """ from Aliases?","Yes|No","Remove Alias");
if (!id) return;
//Output("Favorites ALIAS=delete NAME="+Mid(alias,1));
if (Run("Favorites ALIAS=delete NAME="""+Mid(alias,1)+""""))
	Dialog("r","""" + alias + """ removed!","OK","Remove Alias");

This works on its own, thanks. How might I incorporate it into my existing menu button?

Just read the Evaluation insertion code link I posted above, and include in {=...=}the whole Resolve part as well as the Mid function. You'll figure it out. :wink:

Thanks for the hints. I will continue investigating.

Getting nowhere with this. Not understanding the Mid() reference. This is what I have:

Path.dcf (2.9 KB)

When attempting to use the function, it throws this error:

Assume this is because the button type is set to Standard Function, which is purposely done to accommodate the @keydown arguments.

Yeah, well, the info is there, but I get that it can be tricky to go from documentation to action.
Try with:
Favorites ALIAS=delete NAME="{=Mid(Resolve(source,"aef"),1)=}"
(Assuming that you already know the alias target is correct and you don't want any confirmation dialog)

Note how we can invoke some Evaluator wizardry using the {=...=} part :wink:

1 Like

This works well, thanks! Is the reason for using Mid to eliminate the "/" prior to the actual alias?

Yes, the alias name does not include the preceding "/". The FilePart() function also works.

Just a reminder, if Resolve() returns false, Mid() and FilePart() will respectively return alse and false, your command will attempt to delete the alias with that name.

You can use the Evaluator-generated command line to avoid that situation. However, I don't think anyone would name an alias as "alse" or "false" :slightly_smiling_face:.

= alias = Resolve(source,"aef"); if(alias) return "Favorites ALIAS=delete NAME=" + FilePart(alias);