There have been some recent hints about controlling windows and selecting similar files using AppleScripts, so I thought I would share one that toggles the sort column (kind, date modified etc.) and sort order (a-z or z-a) for a Finder window.
I wanted to do this from the keyboard, so I wrote this script and substituted the appropriate column name as the title, and then assigned it a keyboard shortcut in Quicksilver. Now I can change sort columns and order from the keyboard.
tell application "Finder"
-- could take out the activate if you want
activate
-- In case the column you want to sort by is not visible, turn it on. This example uses the Size column.
if visible of column id size column of list view options of window 1 is false then
set visible of column id size column of list view options of window 1 to true
end if
-- in case that column you want is not currently the one that is selected for sorting, this changes it.
if sort column of list view options of window 1 is not size column then
set sort column of list view options of window 1 to column id size column of list view options of window 1
end if
-- toggles the sort direction, repeatedly invoking the script again has the effect of changing the sort order.
if sort direction of column id size column of list view options of window 1 is normal then
set sort direction of column id size column of list view options of window 1 to reversed
else
set sort direction of column id size column of list view options of window 1 to normal
end if
end tell
-- switch the name of the column using any of the following names, name column, modification date column, size column, kind, column, label column, comment column to change what you will sort on.
Figuring out how to access columns and manipulate them is, well, non-intuitive to say the least, even with the UI Inspector. I hope this script helps others who want to add similar functionality to their Macs.
[kirkmc adds: As explained at the end of the script, change the column named in the script as necessary to act on the column you want. But you can save a script for each column you want to use.]
The Macbook Pro trackpad is very sensitive, and this falsely triggers the Accidental Input detection in Tiger. The result is that the trackpad seems to lock up for a few seconds.
The fix is easy enough: go to System Preferences > Keyboard and Mouse > Trackpad, and uncheck Ignore accidental trackpad input. I turned that feature off and I haven't had any further problems with the trackpad not responding.
Ever wanted to quickly select all similar types of files among a bunch of others in a Finder window? I often find myself having to select, for instance, all the JPEG images amoung docs and movies, etc.
I don't want to change the view, sort by type, and then manually select all the JPEGs; that's so 90's! Instead, try this AppleScript:
try
tell application "Finder" to set the source_folder ¬
to (folder of the front window) as alias
on error -- no open folder windows
--set the source_folder to path to desktop folder as alias
--problem is a window can be open but out of focus
beep
end try
tell application "Finder"
set selectionList to {} & selection as list
set selectedCount to count items in selectionList
if selectedCount > 0 then
set nameExtension to name extension of item 1 in selectionList
select (every item where name extension ¬
is nameExtension) of (folder source_folder)
end if
end tell
[robg adds: This is a very handy timesaver, even in this era of Spotlight. To use the script, enter it in Script Editor, and save it to your user's Library -> Scripts folder. Make sure the Scripts menu is enabled (10.3: Applications -> AppleScript -> Install Script Menu; 10.4: Applications -> AppleScript -> AppleScript Utility). Once saved into the Scripts folder, switch to the Finder and select an item whose type you'd like to select, then select the script you saved from the Scripts menu. Bingo, all similar types will be selected.
I also turned the script into an Automator plug-in for the Finder. Launch Automator and pick the Automator action, and drag Run AppleScript from Library into the work area. Paste the above code, then choose File: Save as Plug-in, and make sure it's set as a Finder plug-in. This works well, except that the chosen folder loses focus at the end of the action, which doesn't happen if you run the script natively.]
The recent discussion on hiding a file's extension led me to write this AppleScript:
on open (ItemList)
set FileList to {}
set FolderList to {}
tell application "Finder"
repeat with thisItem in ItemList
if kind of thisItem is "folder" then
copy thisItem to end of FolderList
else
copy thisItem to end of FileList
end if
end repeat
end tell
my processFiles(FileList)
repeat with thisFolder in FolderList
my splitFoldersFromFiles(thisFolder)
end repeat
end open
on splitFoldersFromFiles(inputFolder)
tell application "Finder"
my processFiles(get files of inputFolder)
set FolderList to folders of inputFolder
repeat with thisFolder in FolderList
my splitFoldersFromFiles(thisFolder)
end repeat
end tell
end splitFoldersFromFiles
on processFiles(FileList)
repeat with thisFile in FileList
tell application "Finder"
set extension hidden of thisFile to true
end tell
end repeat
end processFiles
Save it as an application, and it will become a droplet. Simply drag files and/or folders containing files whose extension you wish to hide onto the droplet, and they'll be hidden.
You can have a folder that maintains its item count in its name. Just attach the following script via Folder Actions:
on adding folder items to thisFolder after receiving addedItems
my setTheCount(thisFolder)
end adding folder items to
on removing folder items from thisFolder after losing addedItems
my setTheCount(thisFolder)
end removing folder items from
on setTheCount(theFolderAlias)
tell application "Finder"
set theFolder to (folder theFolderAlias)
set myCount to the count of (every item of theFolder)
set nameEnd to ""
if myCount > 0 then set nameEnd to " (" & myCount & ")"
set name of theFolder to (comment of theFolder) & nameEnd
end tell
end setTheCount
And then set the comment of that folder (under Get Info) to the name of the folder. As you add and remove items, the name of the folder will include its item count (for example, Downloads (5)). I tested this with Safari, and it's smart enough to maintain your Downloads folder across the rename.
[robg adds: To use this script, save it as a script to your user's Library -> Scripts -> Folder Action Scripts folder. Then control-click the folder you wish to track and select Attach Folder Action (assuming you've previously enabled Folder Actions). Navigate to the Folder Action Scripts folder and choose the script you just saved. Remember to add the folder's name in the Get Info Comments area, and it should work as described -- it did when I tested it on 10.4.6.]
Slow: Highlight file, press Command-I, check the Hide Extension box.
Fast: Remove the extension by renaming the file without the .xyz extension in the Finder.
[robg adds: I'm not sure how well documented this is, but I've used the same trick for quite a while, and I don't think we've run it here before. Removing the extension won't affect your ability to open the file via a double-click on the Mac, but it is destructive, whereas Hide is not. If you're going to move the file to a PC, you'll want to add the extension back on.]
I ran into a problem after I enabled permissions on an external FireWire drive: my non-administrative user could not move anything on that drive to the Trash. When trying to "Move to Trash" any file or folder, the user was presented with the warning that "The item '[filename]' will be deleted immediately. Are you sure you want to continue?" The user could still use the Trash for items on the boot drive or in their home directory.
Despite numerous attempts at fixing the ownership and permissions of the files, the .Trashes folder, and the drive itself, I came upon this solution: delete the .Trashes folders, then relaunch the Finder. This recent hint discusses how to solve similar issues in one's home directory.
If you start in the Terminal as a non-administrative user, first switch to an admin user with:
su admin_username
Then move to the root of the affected drive and remove the .Trashes folder:
$ cd /Volumes/<volume name>
$ rm -rf .Trashes
Finally, relaunch the Finder by holding down the Control and Option keys while clicking on the Finder's icon in the Dock. The .Trashes folder will be recreated, and all users should now be able to use the Trash as expected.
As discussed in this hint, Mac OS X's Finder tends to get very slow when you have a lot of desktop icons. Here's one way to speed things up:
Use the shareware app DeskShade to hide the Desktop, then open a new Finder window and navigate to the Desktop. Organize the files to your liking (preferably with the goal being to remove as many items from the Desktop folder as possible), then unhide the Desktop.
Also of note: as long as DeskShade is hiding the Desktop, the Finder behaves. So you don't ever have to reorganize your Desktop, you just have to keep it hidden most of the time using DeskShade.
[robg adds: If simply hiding the icons on the desktop is an effective fix (I haven't tested that theory), then an alternative solution would be John Haney's free Backdrop, which can be used to hide icons on the Desktop when the floating level is set to "in between." You won't, however, get all of the niceties you get with DeskShade, such as the ability to rotate desktop images, etc.]
I was working on something yesterday when, all of the sudden, the Finder closed and opened, then closed and opened again, and again, and again until it was annoying and became apparent that it was a loop. First I restarted, but it was the same all over. I then tried to login as another user, and everything was just fine. So I was puzzled; I tried some stuff like open firmware restart and single user mode, but couldn't do anything -- the Finder kept crashing.
So I tried Google (some apps actually worked when this was happening), and I got some leads on macosxhints.com, but these tips didn't help me out. They did, however, get me thinking that it probably was a file on the Desktop that was causing the loop (I had a desktop full of stuff) ... and Path Finder was mentioned on one of the websites I had googled.
So I downloaded a Path Finder demo from cocoatech.com, and managed to open it because I had to be faster than the crashing Finder. When I finally opened it, I made a new folder on my hard drive and moved all the files I had on the Desktop to the new folder.
I did not even needed to reboot; the crashing Finder loop was over. So I don't know which file originated this, but it was finally done. It took me more than three hours to figure it out. If you have this symptom on your Mac, maybe my little horror story can help you out -- and give Path Finder a try.
[robg adds: While Path Finder is indeed worth trying (it's a previous Pick of the Week winner here), there's another somewhat more straightforward solution to this problem. Logged in as the second user, just use sudo mv in the Terminal to move all of the troublesome user's Desktop files to a new spot:
Recently my Finder's contextual menu (right-click) menu has been taking an age (five seconds or so) to pop-up. Logging out and in fixes it, but not for long.
So I tried removing various items from ~/Library -> Contextual Menu Items and /System -> Library -> Contextual Menu Items and restarting Finder. It turns out that the culprit was FolderActionsMenu.plugin, in the System-level Contextual Menu Items folder. I have no idea why it makes things so slow (the Folder Actions Setup dialog is really unresponsive, which may have something to do with it), but moving it out of the Contextual Menu Items folder (as root or sudo) has made everything better.
You can still configure Folder Actions using the scripts in the Script menu's Folder Actions folder.
[robg adds: I haven't noticed a slowdown on either of my machines. If you're going to try this fix, don't delete the file, just relocate it elsewhere -- you may wish to put it back at some point.]