Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apple Script: how to delete a file

Tags:

applescript

I am trying to delete a hidden file that shows up every time I restart my computer with an Apple Script set to run on startup. I can't however seem to be able to correctly guess the path of this file.

The file's path is Macintosh HD/Users/cristian/Dropbox (Hyperion)/Hyperion Team Folder/Icon

If I move the file to the desktop and run the script bellow, it works.

tell application "Finder"
    delete the file "Icon
" of the desktop
end tell

My question is, how do I change this script to target the path above? Also, is there anyway to permanently delete it not just move it to the trash?

Thanks in advance.

like image 593
CristianMoisei Avatar asked Oct 20 '25 10:10

CristianMoisei


2 Answers

Assuming there is no new line character at the end of the file name this code deletes the file in the Dropbox folder and empties the trash.

Be aware that the empty trash command affects all items in the trash not only the currently deleted file.

set iconFile to ((path to home folder as text) & "Dropbox (Hyperion):Hyperion Team Folder:Icon"
tell application "Finder"
    delete file iconFile
    empty trash
end tell

Alternatively use the shell to delete the file, in this case the file will be deleted immediately.

set iconFile to POSIX path of (path to home folder) & "Dropbox (Hyperion)/Hyperion Team Folder/Icon"
do shell script "/bin/rm " & quoted form of iconFile
like image 103
vadian Avatar answered Oct 22 '25 03:10

vadian


just use a do shell script command "rm" which delete file directly (without transfer to trash), like in script bellow :

Set myFile to "Macintosh HD/Users/cristian/Dropbox (Hyperion)/Hyperion Team Folder/Icon"
try
do shell script "rm " & quoted form of myFile
end try

However, it should be better to understand root cause why this file is added every time, and then address this root cause.

like image 30
pbell Avatar answered Oct 22 '25 04:10

pbell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!