Thanks all this is a great community and I am very pleased to be a minor part of it …
I have these TextEdit packages with rtfd extension. They contain pictures and an RTF Text file.
I have tried some scripts which I found here but none seems to do what I need at least with Snow Leopard.
I hope to be able to:
1 open the file which will reside on the desktop (finder allows mw to see the pack content)
2 Copy the TXT.file inside the package
3 Transfer the file to a folder calling it with the current date as YYYY-MM-DD
4 Transfer the original rtfd file in the same folder as the previous TXT.File and Rename it with YYYY-MM-DD mms.sec
While some scripts do parts of ewhat I hope to do, I didn’t find anything which allows to open the package and transfer the file. Maybe because I am not comfortable with the TERMINAL. In any case I am unable to merge what I’ve found in one script.
Is this possible?
Model: POWER MAC Intel
Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)
I don’t really understand what you’re aiming for so I made you a little RTFD unpacker
Structure:
Script:
set rtfdFile to (choose file with prompt "Choose the RTFD file.")
set destFolder to (choose folder with prompt "Choose the folder the unpack the RTF")
set packageContents to list folder rtfdFile
-- copy RTF file
set rtfSource to (rtfdFile as text) & "TXT.rtf"
if not fileExistsAtPath(rtfSource) then
display alert "No Valid RTFD" message "The chosen file is not a valid RTF file with attachmetns. The 'TXT.rtf'-file was not found."
return
end if
copyFile(rtfSource, destFolder)
-- copy attachments
set attFolder to (destFolder as text) & "RTF Attachments"
if not fileExistsAtPath(attFolder) then mkdir(attFolder)
repeat with i in packageContents
if (contents of i) is not "TXT.rtf" then
set attFile to (rtfdFile as text) & i
copyFile(attFile, attFolder)
end if
end repeat
display dialog "RTFD Unpacked"
(* ===== HANDLERS =====*)
on copyFile(fSource, fDest)
do shell script "cp " & ¬
quoted form of POSIX path of fSource & ¬
space ¬
& quoted form of POSIX path of fDest
end copyFile
on mkdir(aHSF)
do shell script "mkdir " & quoted form of POSIX path of aHSF
end mkdir
on fileExistsAtPath(aHSF)
set aHSF to aHSF as text
try
get aHSF as alias
return true
on error
return false
end try
end fileExistsAtPath
try this, select some files in the Finder and run the script.
The folder archiveFolder will be created on desktop
and the intermediate date directories will be created automatically.
At the end of the script is a delay to avoid files with the same timestamp,
because AppleScript is able to process more than one file per second
property archiveFolder : "Archive"
tell application "Finder" to set sel to (get selection)
set destinationFolder to POSIX path of (path to desktop) & archiveFolder & "/"
repeat with oneFile in sel
if name extension of (info for oneFile as alias) is "rtfd" then
set now to do shell script "/bin/date +%Y-%m-%d-%H%M%S"
set today to text 1 thru 10 of now
set sourceFile to quoted form of (POSIX path of (oneFile as text) & "/TXT.rtf")
do shell script "/usr/bin/ditto " & sourceFile & space & quoted form of (destinationFolder & today & "/" & now & ".rtf")
do shell script "/bin/mv " & quoted form of POSIX path of (oneFile as text) & space & quoted form of (destinationFolder & today & "/" & now & ".rtfd")
delay 1.5 -- avoid timestamp clash
end if
end repeat
I also send you as a sample another script I created using ideas form several other scripts to get the content of an RTF link in plain text.
You tried to help before … however this seems to be a good solution. Of course I need to change the incremental values each time but since I never get too many this is no problem really.
activate application "TextEdit"
repeat with theIncrementValue from 1 to 1
tell application "System Events"
tell process "textedit"
keystroke "k" using {command down}
keystroke "a" using {command down}
keystroke "c" using {command down}
key code 53
keystroke "v" using {command down}
keystroke "g" using {command down}
end tell
end tell
end repeat
Model: POWER MAC Intel
Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)