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


Click here to return to the '10.6: Another way to view any text file in Quick Look' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6: Another way to view any text file in Quick Look
Authored by: asmeurer on Jan 14, '10 12:03:43PM
I got so tired of QuickLook showing my an icon instead of the text of a plain text file that doesn't end in .txt, that I wrote this AppleScript:

on run
	tell application "Finder"
		set theitems to the selection as alias
		showthefiles(theitems)
	end tell
end run
on open (opened)
	set theitems to opened as alias
	showthefiles(theitems)
end open
on showthefiles(theitems)
	set thescript to ("qlmanage -p -c public.plain-text " & the quoted form of the POSIX path of theitems)
	do shell script thescript
end showthefiles
Save it as a drop script and put it in the Finder toolbar. You can then drag a plaintext file onto it to open a QuickLook window that will show you the contents. The only down side is that you have to close it by hand. Also, this should work just by selecting the file and clicking on the script in the toolbar, but I get an error. Any AppleScript gurus out there know what I am doing wrong?

[ Reply to This | # ]
10.6: Another way to view any text file in Quick Look
Authored by: mr. applescript on Jan 14, '10 10:35:01PM
A couple things: 1) inside the Run handler: use "as alias list" to have the Finder return references to the currently selected items as a list of references in alias format 2) in the Open handler: you don't need to coerce the input to an alias list, they already are by default 3) in the sub-routine: you have to create a space-delimited string of posix references by iterating the list of alias references, like this:
on showthefiles(theitems)
	repeat with i from 1 to the count of theitems
		set this_path to the quoted form of the POSIX path of (item i of theitems)
		if i is 1 then
			set the POSIX_list to this_path
		else
			set the POSIX_list to the POSIX_list & space & this_path
		end if
	end repeat
	set thescript to ("qlmanage -p -c public.plain-text " & POSIX_list)
	do shell script thescript
end showthefiles


[ Reply to This | # ]
10.6: Another way to view any text file in Quick Look
Authored by: mr. applescript on Jan 14, '10 11:32:16PM
FYI, a QuickLook Droplet is already available and posted on MACOSXAUTOMATION.COM. http://macosxautomation.com/applescript/quickviewer/index.html

[ Reply to This | # ]