I have used xattr -d com.apple.quarantine /Users/username/Desktop/app_name.app to remove the attribute but I don't know how to give the attribute again. Could you please help me?
You should be able to do this by replacing the
-d (delete) flag with
-w (write). So:
xattr -w com.apple.quarantine /Users/username/Desktop/app_name.app
A handy tip if you are unsure about a command is to look up the man page for it.
If you type
man xattr it will give you a list of available options for that command with explanations. (to navigate the manual use the arrow keys and press the
q key to quit.)
The attribute is not just a flag: it contains a sequence of meaningful bytes. (The
-w option of
xattr requires attribute data to write to the file.)
Here's an example of the contents from a file in my Downloads folder:
Unless you can recreate the correct data manually, or already have the old metadata for that file in a backup (in which case you might as well just restore the whole file), introducing the wrong quarantine data may cause unexpected problems.
It is somewhat odd to re-introduce quarantine, as that suggests you no longer trust the file.