I searched the internet and this forum, but couldn’t find the solution unfortunately.
I have a folder with hundreds of .rtf-files, each containing some formatted letters and numbers.
I want to batch convert each of these files to a folder with the same amount of textclippings keeping the formatted letters and numbers.
Is this possible with Applescript? Do you have a solution?
thank you very much for the script. Much appreciated. Works like a charm.
Is there a way that the contents (Rich-Text) of the textclipping can be previewed in Spotlight with Quickview?
I refined it little and made it useful handler for me:
use framework "Foundation"
use scripting additions
set theFiles to (choose file of type {"public.rtf"} with multiple selections allowed)
createTextClippings(theFiles)
on createTextClippings(theFiles) -- theFiles is aliases list parameter
repeat with theFile in theFiles
-- Get the source's Posix path, NSURL, basename
set posixPath to POSIX path of theFile
set containerPosixPath to (((current application's NSString's stringWithString:posixPath)'s stringByDeletingLastPathComponent()) as text) & "/"
set theURL to (current application's |NSURL|'s fileURLWithPath:posixPath)
set basename to theURL's lastPathComponent()'s stringByDeletingPathExtension()
-- Create the dictionary for text clipping file
set rtfString to (current application's NSString's stringWithContentsOfURL:theURL encoding:(current application's NSUTF8StringEncoding) |error|:(missing value))
set theObjects to current application's NSMutableDictionary's dictionary()
(theObjects's setObject:rtfString forKey:"public.rtf")
set newDict to current application's NSMutableDictionary's dictionary()
(newDict's setObject:theObjects forKey:"UTI-Data")
-- Write .textclipping file at parent directory
set theURL to (current application's |NSURL|'s fileURLWithPath:(containerPosixPath & basename & ".textClipping"))
(newDict's writeToURL:theURL atomically:true)
end repeat
end createTextClippings