I’d like to create a script to run every evening that cleans our windows shares of the “._” files that appear. Can you tell me how to create a script like this, please:
dot_clean /volumes/
This is a script I’ve created so far, but it’s saying ‘permission denied’.
do shell scripts"~/ desktop / dot_cleanscript.rtf" password “password” with administrator privileges
I’ve also created two files:
dot_cleanscript.sh
contains: dot_clean /volumes/
scheduledscript.scpt
contains:
tell application “Terminal”
activate
do script “cd /volumes/Macintosh HD”
do script “/users/“computername”/desktop/dot_cleanscript.scpt”
end tell
this gives these results:
/users/“computername”/desktop/dot_cleanscript.scpt
mac:~ “computername”$ /users/“computername”/desktop/dot_cleanscript.scpt
-bash: /users/“computername”/desktop/dot_cleanscript.scpt: Permission denied
Same results as the first script: Permission Denied!!
The “Permission denied” error when trying to run a program (including shell scripts) usually means that the execute permission is not enabled for the program’s file. You usually use the chmod command to enable the execute permission: “chmod +x /path/to/file”.
Also, it is a good idea to include a hash-bang line at the very top of shell scripts: “#!/bin/sh”. Including this as the very first line tells the kernel which shell interpreter you want to use for the script when it is run directly. If you are writing only Bourne shell scripts that you will only ever use on your machine you can get away without it. Otherwise, including such a hash-bang is either a good idea (for running on other machines, Mac OS X releases, or other OSes) or required (for non“Bourne shell languages).
If your AppleScript file is a plain text file with just the AppleScript code, it should probably have the extension “applescript” (“scpt” is used for compiled scripts that are binary files; they can even be empty files with all the data in their resource fork).
AppleScript files can not be run directly by other programs. If you have an AppleScript file (with the corresponding usual extension), you can run it by using the osascript program. “osascript /path/to/file.applescript” and “osascript /path/to/file.scpt” will both work. A slight exception to this “not directly runnable” rule is that, on Leopard, you can use a hash-bang line of (for example) “#!/usr/bin/osascript” in an “applescript”-type file to let it be run directly (still requires execute permission, like any other hash-bang program).
There seem to be some syntax problems here, on multiple levels. First, the AppleScript command is do shell script (no “s” on the end). Second, there are extra spaces in your code there. If you actually give that string to do shell script it would probably give you an “sh: line 1: /Users/whoever/: is a directory” error. So, I will assume that these problems were introduced by re-typing the code instead of pasting it into your post. It is also best to let us see the exact code you are using, not a re-typed version. Otherwise we can not tell if the errors we see are from the re-typing or are actually in the program.
Beyond syntax, you appear to be trying to directly run a RTF (Rich Text Format) file. This is highly unlikely to succeed. Although RTF is a plain text format, it adds extra “code” to any text that you actually type (to preserve formatting). Because of this extra “code”, an RTF file will be useless as a shell script. If you are using TextEdit to edit your shell script, you should use Format > Make Plain Text and re-save it. Which encoding you use depends on which tools you are actually using in the shell script. If the default is UTF-16, switch to UTF-8, otherwise probably the default encoding is fine (it will probably default to Mac OS Roman; either of the Latin 1 variants are OK; anything that encodes the ASCII repertoire to the usual 8-bit ASCII values should work). When saving it you will likely end up with a default extension of “txt”. While that will work just fine it looks a bit odd to have a shell script in a “txt” file. A common extension for shell scripts is “sh”. You can even arrange for TextEdit to be the default editor for “sh” files (in Finder, select a “sh” file, File > Get Info, then under “Open with:”, pick “Other.”, pick TextEdit, check “Always Open With”, click “Add”, close the info window).
Last, it looks like you have something running an AppleScript program that starts a shell script in Terminal, which starts another shell script, which maybe starts another shell script. You probably do not need all those layers. You might be able to just put everything into one shell script and run that in an AppleScript with do shell script (no Terminal needed). If your scheduler can run shell scripts and not just AppleScript programs, you may not even need AppleScript at all (assuming that you cleaning is done in shell, not AppleScript). Or, if your cleanup code is in AppleScript, you may not even need any shell scripts.
I have written a script to automate this process but for what ever reason on 10.5.8 when I do a dot_clean it doesn’t seem to be removing the files that start with a dot that are hidden. I have set the Finder to show hidden files and have run step six in the first link from the terminal even and it doesn’t seem to trash the hidden files.
I am not sure if the following script I have written is the same thing as what dot_clean is suppose to do but if it is this seems to clean out all the hidden files.
The dot clean thing which is explained and discussed pretty thoroughly in This Article about new unix commands in Leopard By Rob Griffiths explains how you can get rid of the . and ._ files by joining them with their parent files by using the then new dot_clean command.
So by deleting them you take a different approach. Your scripts seems to be very cool, I’ll think I’ll loot you.
Aside: I use to take advantage of the .DS_Store files in Finder, to have a “safe spot” to drop files onto, in order to get them into that folder instead of down in some child folder.
Just a quick update on the script, which is not the “dot_clean” I of course was really after, I found that I often had to run it multiple times to get it to delete all the files every time but this seems to solve the problem.
set thumbDrive to "/Volumes/FilterStik"
try
do shell script "find " & thumbDrive & " -name '.Trashes' -exec rm -R -f {} \\;"
end try
try
do shell script "find " & thumbDrive & " -name '.Spotlight-V100' -exec rm -R -f {} \\;"
end try
try
do shell script "find " & thumbDrive & " -name '.fseventsd' -exec rm -R -f {} \\;"
end try
try
do shell script "find " & thumbDrive & " -name '.TemporaryItems' -exec rm -R -f {} \\;"
end try
try
do shell script "find " & thumbDrive & " -name '._.DS_Store' -exec rm -R -f {} \\;"
end try
try
do shell script "find " & thumbDrive & " -name '.Thumbs.db' -exec rm -R -f {} \\;"
end try
try
do shell script "find " & thumbDrive & " -name '.*' -exec rm -R -f {} \\;"
end try
try
do shell script "find " & thumbDrive & " -name '._.*' -exec rm -R -f {} \\;"
end try
Just to save any noob like me the time here is the way to do a dot_clean. I have confirmed this by moving the drive back and forth to Windows XP.
set thumbDrive to "/Volumes/FilterStik"
try
do shell script "dot_clean " & thumbDrive & ""
end try
Just obveously change the name “FilterStik” to what ever your drive name is. It seems interesting that even if you have hidden files shown in the Finder it will still not show files with ._ or resource forks, if I am using that term properly?
Sorry I am sure that was obveous thanks for going easy on me you are kind.
The .DS_Storefiles is an exception to the rule I believe. To be honest with you, I have never noticed any of the other files on my usb-pens. I just do a fast reformat them via diskutil.
It’s been a long time since I have used one of them though. Due to the risk for viruses.
Invisible files shows up in finder, but I’m not sure about the Resource forks, (I think you use the term correctly) or the split resource fork maybe, as it should have gone with the file on a HFS filesystem, but can’t on a say FAT32 system, and therefore is created as a separate file.
So you may see files starting with a dot in Finder, but that’s pretty much all you can do with it from there.
If I’m not dreaming I think that any access to a file starting with a dot is prohibited from within Finder via AppleScript.
We are all noobs here, in one aspect or another, maybe with a couple of exceptions, but I’m not one of those.