Applescript to automatically add .noindex extension to a file?
I'm interested in excluding certain files from Spotlight, and it was suggested to add the .noindex
extension. I'd like to automate this. How is it possible to do via Applescript?
Solution 1:
The following AppleScript will append the extension .noindex
to any single file. To use this particular script, paste it into a new AppleScript document and save it as an Application. It will have a Application like icon with an arrow. This means the script is a droplet. To rename any single file, simply drop the file on top of this application's icon, and the file will have been renamed in under a second.
on open theFileToRename
tell theFileToRename
tell application "Finder"
set theName to the name of file theFileToRename as string
set extension to ".noindex"
set the name of file theFileToRename to (theName & extension)
end tell
end tell
end open
If you don't want to use the functionality of Droplets, the following script will prompt you to select a file:
set extension to ".noindex"
set theFileToRename to (choose file with prompt "Select a file to append the \"" & extension & "\" extension to." without multiple selections allowed)
tell application "Finder"
set theName to the name of file theFileToRename as string
set extension to ".noindex"
set the name of file theFileToRename to (theName & extension)
end tell
I hope this is useful to you.
Solution 2:
You can use simple command inside Terminal.app to rename all files in directory including subdirectories. Navigate to directory in which You have files to rename (cd /path/to/dir
) and run this command:
find . -name "*\.txt" -exec bash -c 'mv "{}" "{}.noindex"' \;
This will rename all txt
files. Change extension to whatever You want.