tell application "Finder"
set deletedfile to alias "Snow Leopard:Users:test.pdf"
delete deletedfile
end tell
The problem is I repeatedly call this script from my Cocoa application so the sound is played repeatedly too. Is it possible to disable that sound ?
Since the trash is just an invisible folder inside your home folder you can do this...
set myFile to (path to desktop folder as text) & "myFile.txt"
set trashFolder to path to trash folder from user domain
do shell script "mv " & quoted form of POSIX path of myFile & space & quoted form of POSIX path of trashFolder
one simple way (doesn't move to Trash)
do shell script "rm '/Users/test.pdf'"
Related
I've been trying to find a program or some sort of app to run all the time and check one folder. If any document would be saved in the folder it would rename it like file1.png the next one file2.png.
Transnomino has an automation feature that allows to automatically rename any file dropped in a folder using a specified renaming Recipe. The Apple Script that does this looks something like this:
on adding folder items to theAttachedFolder after receiving theNewItems
tell application "Finder" to set thePath to POSIX path of theAttachedFolder
return do shell script ¬
"open -a Transnomino --args -d \"" & thePath & "\" -r \"" & thePath & ".recipe\""
end adding folder items to
A complete guide how this can be setup is described on the website of Transnomino. Here: https://transnomino.bastiaanverreijt.com/automation/index.html
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.
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
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.
I am currently setting up an ApplescriptObjC application. Whenever I try other methods, it screws up. I'm trying to set it up where a shell script uses the mv command to move a file from the "Files" directory to the /usr/bin/ folder. I think it would go a little something like: do shell script "sudo mv " & path & "/Files/ /usr/bin/" where path would be the path to me. I have tried the path to me and posix and other stuff, just doesn't work. ![The Files folder contains a file I want to move to /usr/bin] Image of where the folder is: http://i.stack.imgur.com/jUX6w.png
First of all the folder Files in your screenshot is a virtual folder in Xcode (yellow).
You have to create a real folder (blue). The easiest way is to drag a folder in Finder to the Xcode sidebar and select "Create folder references"
To use sudo in AppleScript append with administrator privileges to the do shell script line. You will be prompted to enter an admin password.
This code moves(!) the files to /usr/bin. If you want to copy (duplicate) the files use cp -r instead of mv
set filesFolder to (current application's NSBundle's mainBundle()'s resourcePath()'s stringByAppendingPathComponent:"Languages") as text
tell application "System Events" to set filesToMove to name of files of folder filesFolder
repeat with aFile in filesToMove
do shell script "/bin/mv " & quoted form of (filesFolder & "/" & aFile) & space & "/usr/bin/" with administrator privileges
end repeat
I know its a dumb question but somehow the command i type is not working
set deleteFile to srcTemp & "Archive.zip"
--deleteFile path is something like this /Users/home/Desktop/Archive.zip
tell application "Finder"
move POSIX file "" & deleteFile & "" to trash
--move file "\"" & destNoQuote & "Archive.zip\"" to trash
empty the trash
end tell
But I get an error saying can't find the POSIX file.
I know that many people use the posix file command inside the Finder tell block of code however that's a mistake. The posix file command is not a Finder command, it's an applescript command, and therefore should not be in the Finder block if possible. This is true for all commands actually. You should only tell an application to perform the commands you can find inside of its applescript dictionary otherwise you will see unexpected behavior... as you are finding.
As such this is how you should write your code...
set deleteFile to srcTemp & "Archive.zip"
set posixFile to POSIX file deleteFile
--deleteFile path is something like this /Users/home/Desktop/Archive.zip
tell application "Finder"
move posixFile to trash
empty the trash
end tell
Here's another method of your entire script in one line:
do shell script "rm -Rf " & quoted form of (srcTemp & "Archive.zip")
This will force remove your file and it doesn't just go to your trash, it's gone.
I'm creating simple script to convert mp3 files using shell script. I decided to automate my conversion using applescript.
Basically what I'm doing is selecting mp3 file then splitting that file using my command line and i want to create a folder where the file is located (script will create that for me).
Now I just need to figure out how to get a path to a folder of the file.
How do I do that in applescript?
Here is the script that I have so far:
set mp3FileToSplit to choose file without invisibles
set thepath to mp3FileToSplit as text
set theposix to POSIX path of thepath
tell application "Finder" to set file_name to (name of mp3FileToSplit)
do shell script "/opt/local/bin/mp3splt -t 3.00 -d " & quoted form of file_name & " " & quoted form of theposix
Right now what that script does is creating folder on the root of my hard drive and I need to be in the folder where the file is located.
Any help will be appreciated.
tell application "Finder"
set f to POSIX file "/private/etc/" as alias
POSIX path of ((folder of f) as alias) -- /private/
end tell
Or
do shell script "dirname /private/etc/" -- /private