wrapper.applescript
Wrapper.applescript
Saving this code has been altered bacause of Google's CLASSIC to NEW transformation.
If you have an external disk drive, and are annoyed with Spotlight trying to index your external volume(s), you may find this useful. I have DataBackup from prosofteng.com that allows me to create a "clone" backup, but unless the external disk volume has some way to suppress Spotlight, doing such a backup can be time consuming. The AppleScript below is one solution. It places a .metadata_never_index file on your hard drive, runs your backup application, which copies that file to the backup, and then deletes the file on your hard drive. The next time you mount your external disk volume, Spotlight sees the .metadata_never_index file and doesn't attempt to index.
Initially, you may wish to prepare your external drive's volume(s) by applying my stopspot shell script. That not only places .metadata_never_index on your external volume, it reinitializes the .Spotlight-V100 folder on that volume to eliminate any existing index database (db), and sets flags and plists to "disable indexing". The combination of .metadata_never_index and .Spotlight-V100 changes (by mdutil) provide complete protection from indexing the external drive's volume. Of course, if you are doing a "clone" backup, you should Exclude your hard disk's own .Spotlight-V100 folder from being copied to the clone. The empty version on the clone is all you need.
To create your own "metadata" wrapper application, download this script by clicking metadata.applescript and then double-click the resultant file to unpack the downloaded tgz-file. The, double-click the wrapper.code folder, and then double-click the resulting applescript to launch the Script Editor. Make editing changes on "username" and "diskname" and your clone backup application's name (default "DataBackup") using Cmd-F (Find...), entering old after "Find:" and new after "Replace with:", and clicking the "Replace All" button. Save your changes with Cmd-S (Save). Then click the "Compile" button. Now Cmd-Shift-S (Save As...), and choose the application's destination from the left panel, change the "File Format:" option by scrolling to "application", set the "Options:" to have "Run Only" (nothing else), and click the "Save" button. Your own private application will now be ready to launch.
========== metadata.applescript ========
global myUser, myVol
set myVol to ""
------------------
do shell script "sudo -k"
-- get username.
set myUser to (do shell script "echo $USER")
-- verify that user has admin privs.
set myVerify to (do shell script "sudo -u " & myUser & " cd")
if (myVerify is "") then
-- At this point you can customize for a particular user name
-- to check that a particular disk is mounted (your backup disk).
-- In this case, "username" wants "diskname" mounted.
-- Use Find -> Replace All to change username and diskname.
if (myUser is "username") then
try
set myVol to ¬
(do shell script "ls -d /Volumes/* | grep 'diskname'")
end try
if (myVol is "") then
display dialog ¬
"diskname missing" with title ¬
"diskname missing" with icon stop ¬
default button 1
if button returned of result is "Cancel" then
return
end if
end if
end if
------------------
activate
set myVol to ""
try
set myVol to (do shell script "ls /.metadata_never_index 2>/dev/null")
end try
if (myVol is "") then
do shell script ("touch /.metadata_never_index 2>/dev/null")
end if
Update()
if (myVol is "") then
try
do shell script ("rm -f /.metadata_never_index 2>/dev/null")
end try
end if
end if
return
------------------
on Update()
try
-- Replace "DataBackup" by with the name of any other backup application.
tell application "Finder"
launch application "DataBackup"
repeat until (exists process "DataBackup")
delay 1 --wait for DataBackup to be ready
end repeat
activate the front window of application "DataBackup"
set myCnt to 19 as integer
repeat while (exists process "DataBackup")
delay myCnt --wait for DataBackup to finish
if (myCnt > 9) then
set myCnt to (myCnt - 1) as integer
end if
end repeat
end tell
end try
end Update
----------------