Text Clipping to Text File

Hi guys & girls,

I’m trying to write a script that takes Text Clippings and adds them to a text file.

I collect quotes for my sig file, make a text clipping of them and C&P it into sigs.txt once I have a bunch.

What I’d like to have a droplet that adds them to the sigs file.

I’ve searched the forums & googled, but haven’t found anything.

Any help would be greatly appreciated!


Hi libwolf,

I am not fully understanding what you mean by “Text Clipping.”

Is this a Safari “Text Clipping” that creates a Dashboard Widget
or is it just ordinary text from the clipboard?

If it is ordinary text. Are you copying it from Safari?
Is so, it is fairly simple to get the selected text from Safari
and add it to a text file.




do you mean something like this?

on run
	choose file of type "clpt" with multiple selections allowed without invisibles
	open result
end run

on open theFiles
	set sigsText to ((path to desktop as Unicode text) & "sigs.txt")
	repeat with oneFile in theFiles
		if name extension of (info for oneFile) is "textClipping" then
			set theFile to quoted form of POSIX path of oneFile
			set theData to do shell script "/bin/cat " & theFile & "/..namedfork/rsrc"
			set {TID, text item delimiters} to {text item delimiters, ((ASCII character 254) & (ASCII character 255))}
			set theData to text items of theData
			set theData to item 2 of theData
			set text item delimiters to ((ASCII character 0) & (ASCII character 0))
			set theData to text item 1 of theData
			set text item delimiters to TID
			write_to_disk from (theData & return) into sigsText
		end if
	end repeat
end open

on write_to_disk from theData into theFile
		set ff to open for access file theFile with write permission
		write theData to ff starting at eof
		close access ff
		return true
	on error
			close access file theFile
		end try
		return false
	end try
end write_to_disk

Hi Stefan, I don’t know if Libwolf ment… “something like this?”
But your script is very useful to me.

Thank you very much!

Tom :smiley:

Here’s a nice variant that uses the Satimage OSAX:

on run
	choose file of type "clpt" with multiple selections allowed without invisibles
	open (result as list)
end run

on open theItems
	set fRef to (open for access file ((path to desktop as Unicode text) & "sigs.txt") with write permission)
		if ((get eof fRef) is 0) then write «data rdatFEFF» to fRef
		repeat with thisItem in theItems
			if (file type of (info for thisItem) is "clpt") then
				-- The next two lines use the Satimage OSAX.
				set rsrcNum to beginning of (list resources "utxt" from thisItem)
				set txt to (load resource rsrcNum type "utxt" from thisItem)
				write txt & return as Unicode text to fRef starting at eof
			end if
		end repeat
	end try
	close access fRef
end open