Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: Apply Finder labels based on application type Desktop
Tiger only hintHaving just bought a MacBookPro, I wanted a fast and easy way to see what apps I have that are universal, versus the ones that are PowerPC. This AppleScript will apply finder color labels to all of you applications. PowerPC apps are labeled grey, and Intel-only apps are labeled yellow. Universal Apps get no color label.

[robg adds: This earlier hint explained how to use Terminal to return a list of Intel-ready applications, and this hint used a different shell script to find all non-universal applications (with more nicely formatted output). This AppleScript, since it relies on the System Profiler report, will only work for applications located in the /Applications or ~/Applications folders, but it will traverse any subfolders of those directories as well.

If you want to remove the labels at some point, just modify the script so all instances of the set app_type... line read set app_type to 0, and then run it again. The script worked as described when I tested it on my Core Duo mini.]
  Post a comment  •  Comments (4)  
  • Currently 1.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
[7,578 views]  View Printable Version
Get the name of the current desktop image Desktop
I was replying to a question in the forums when I realized that this would make a great tip for the main site. Just like the original poster, I have a lot of desktop images, and sometimes I can't remember the name of the one that's currently displayed when I want to edit it (or trash it). So here's the AppleScript that I came up with to solve that problem...
tell application "System Events"
  set my_desktop to value of (property list item "LastName" of 
  property list item "1983938400" of property list item 
  "Background" of property list file 
  ((path to preferences as Unicode text) & 
  display dialog my_desktop
end tell
This script looks in the file in your user's Library/Preferences folder for the name of the current desktop image. On my Mac running 10.4.5, there are actually several plist items under Background, each of which contain entries for desktop images that are not being displayed, so it took some poking around to find the correct path.

Apparently, there are some variations in the way that this .plist file looks. For this to work on your own system, you should open your own file with the Property List, and see where the value for your current desktop image is kept. Then change the value in the script (1983938400 in the above code) to match the value of the appropriate LastName entry for your current desktop image.

I have my Mac set to cycle through the images kept in a single "Screens," folder and I have double-checked that it will snag the name of the file again after the image has cycled a few times. This also works with two-monitor setups. I'll leave the modification for two monitors to your own ingenuity.
  Post a comment  •  Comments (17)  
  • Currently 2.80 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
[14,139 views]  View Printable Version
Place an alias to anything on either side of the Dock Desktop
In the Dock, applications normally appear on the left side of the divider (or above if the Dock is positioned on the side of the screen), and files and folders appear on the right side (or below).

One exception is a Finder alias, which despite being a file, will appear on the left side if the original to which it points is an application. It appears that this difference can be attributed to the file type of the alias, which may match the file type of the original for files but is set to fapa for aliases to applications. By changing the file type of an alias to or from fapa, it is possible to make it appear on either side of the Dock's dividing line.

To modify a file or folder alias so that it can be placed on the left side of the Dock, use either of these commands, entered using Terminal (in /Applications -> Utilities). The first command requires the Developer Tools be installed, while the second does not:
  1. /Developer/Tools/SetFile -t "fapa" /path/to/FileorFolderalias
  2. osascript -e 'tell application "System Events" to set (file type) of (choose file) to "fapa"'
To modify an application alias to place it on the right, use either of these commands (same rules as above):
  1. /Developer/Tools/SetFile -t "" /path/to/Appalias
  2. osascript -e 'tell application "System Events" to set (file type) of (choose file) to ""'
Read on for some things to be aware of if you want to use this trick...
read more (306 words)   Post a comment  •  Comments (5)  
  • Currently 3.00 / 5
  You rated: 3 / 5 (4 votes cast)
[8,799 views]  View Printable Version
Sort by columns in the Finder from keyboard Desktop
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	
	-- 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
		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.]
  Post a comment  •  Comments (9)  
  • Currently 1.33 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
[10,326 views]  View Printable Version
Resolve Macbook Pro trackpad response issue Desktop
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.

[kirkmc adds: Edited to read 'uncheck'.]
  Post a comment  •  Comments (19)  
  • Currently 1.83 / 5
  You rated: 2 / 5 (18 votes cast)
[105,034 views]  View Printable Version
Select similar files in a Finder window via AppleScript Desktop
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:
  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
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.]
  Post a comment  •  Comments (11)  
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
[16,350 views]  View Printable Version
An AppleScript to hide extensions via drag and drop Desktop
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
        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.
  Post a comment  •  Comments (3)  
  • Currently 3.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
[10,557 views]  View Printable Version
Display folder item counts via folder action script Desktop
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.]
  Post a comment  •  Comments (10)  
  • Currently 3.40 / 5
  You rated: 4 / 5 (5 votes cast)
[14,090 views]  View Printable Version
Hide file extension via rename Desktop
To hide the extension of a file:
  • 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.]
  Post a comment  •  Comments (23)  
  • Currently 1.86 / 5
  You rated: 2 / 5 (7 votes cast)
[18,733 views]  View Printable Version
Fix unusable Trash on other volumes Desktop
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.
  Post a comment  •  Comments (2)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
[5,408 views]  View Printable Version