Can not select and delete alias in /usr/bin folder

Hello, I am new to this forum and although I am impressed by the know how of the users I could not find what I am looking for.
I want to check if a specific alias exists in the folder /usr/bin and if so to delete this alias.
Now I have 2 problems :

  1. If I try Adam Bells code : set lA to paragraphs of (do shell script "mdfind -onlyin " & "'/usr/bin/'" & " 'kMDItemKind == \"Alias\"'")
    the resulting list is empty but I am sure there are several aliases in this folder.

  2. To delete a file in /usr/bin I need permission. The code I have, works for normal accessible folders :

tell application "Finder" set aliasPath to targetFolder as alias set origPath to PathFile as alias set aliasFiles to every file of aliasPath whose class is alias file as list repeat with i from 1 to number of items in aliasFiles set thisItem to item i of aliasFiles set thisAliasName to displayed name of thisItem if thisAliasName is equal to theFile then delete thisItem display dialog "The alias is removed" buttons {"OK"} end if end repeat end tell
Any help will be much apreciated

Hi,

welcome to MacScripter

the folder /usr/bin belongs to the root user (the operating system), a normal user is not allowed to change files.

The system needs those alias files for certain reasons, so you should not delete them.
Binary executables which belong to a user should be saved somewhere else

Anyway, assuming that you know what you are doing, you can delete any file with the shell.
With the sudo command you can obtain root privileges.
The AppleScript equivalent to the sudo command is

try
	do shell script "/bin/rm /usr/bin/myExecutableAlias" user name "myUser" password "¢¢¢¢¢¢" with administrator privileges
end try

¢ The parameter user name can be omitted, if the current user has admin status
¢ The try block avoids any error message, e.g. in case the file does not exist

Consider that rm deletes the file immediately and permanently

Also remember that hard link or symbolic link files in /user/bin are no alias files. You’re in the world of unix here and using the BSD file system instead of the carbon file system. Alias and hard link or symbolic links are different from each other. An hard link caries the node of a file and bypasses the names. Therefore can a hard link can act as a file and is also the main reason why there are hard links stored. Many applications rely on those links like /etc behaves like a folder stored on the root of your drive while it is stored in the private folder. in the /user/bin folder there are many hard links stored to frameworks in your system folder. Many applications can’t find the frameworks anymore and won’t work if they use dynamic libraries like applications written in Java.

Thank you for the explanation and the warnings.
I think I should explain the situation in more detail.
I run a chess program called Xboard in /Applications/Xboard. This program can use a number of so called engines which are located in /Applications/Xboard/Engines
For every engine there is a link in /usr/bin. If you want to use a new engine you have to create the link with “sudo ln -s /Application/Xboard/Engines/new_engine /usr/bin” in the terminal. And when you remove an engine you should also remove the link.
What I intended to do was to script this process, so check if a link (with the same name) for the new engine already exists an if so remove the link and subsequently create a fresh link for the new engine.

I am stuck because I can not get a script that will show the links in /usr/bin although “get info” will give me “Kind=Alias” for the links