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


Click here to return to the 'Select similar files in a Finder window via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Select similar files in a Finder window via AppleScript
Authored by: Lutin on Apr 20, '06 06:39:43AM
I liked that idea so much that I made an other version which work with the name of the file (stripped of its extension).
A dialog box lets the possibility to modify the string if necessary.

I binded it to Command-F2 with Quicksilver, and it's a huge time-saver.

-- In column mode, if the final selection is only folders, it doesn't work as expected
-- The selection is only the last folder of the window.
-- Works fine in other view mode
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 toselectList to {}
	
	-- Get the current selection
	set selectionList to {} & selection as list
	
	-- Be sure the selection isn't empty
	set selectedCount to count items in selectionList
	if selectedCount > 0 then
		
		-- Get the first file selected
		set thefile to item 1 of selectionList
		
		-- Get the file of the name without its extension
		set filename to name of thefile
		
		set fileextension to name extension of thefile
		if (fileextension is not "") then
			set ix to offset of fileextension in filename
			set filename_withoutext to characters 1 thru (ix - 2) of filename as string
		else
			set filename_withoutext to filename
		end if
		
		
		-- Ask for the string to match	
		set matching_str to display dialog "Set the string you want to match:" default answer (filename_withoutext) buttons {"Cancel", "Continue"} default button "Continue"
		
		-- Get all the elements of the folder
		set allList to (every item of folder source_folder)
		
		-- Add the files with name matching to the list allList
		repeat with file_item in allList
			if (text returned of matching_str) is in name of file_item then
				set end of toselectList to file_item
			end if
		end repeat
		
		-- Select the files
		select (every item of toselectList)
	end if
end tell

I still have the same bug, and no idea how to fix it.

[ Reply to This | # ]