-
-
Save dpinney/f5de675274c9f1ad16df6794d614dea8 to your computer and use it in GitHub Desktop.
# We do this with Pages because it's the only thing that can correctly convert rtfd. | |
# textutil works on rtf files with no text in them but not on rtfd. | |
set my_paths to {"/path/to/first/file.rtfd", "/path/to/second/file.rtfd"} | |
repeat with my_path in my_paths | |
tell application "Pages" | |
set my_file to (my_path as POSIX file) | |
set my_name to name of (info for my_file) | |
set doc to open my_file | |
export doc as Microsoft Word to alias (my_path & ".docx" as POSIX file) | |
close doc | |
tell application "Finder" to delete my_file | |
end tell | |
end repeat |
I am making headway: I just managed to get it to work when choosing the file:
tell application "Finder" to get POSIX path of (choose file)
get POSIX path of result
set my_paths to {result}
repeat with my_path in my_paths
tell application "Pages"
set my_file to (my_path as POSIX file)
set my_name to name of (info for my_file)
set doc to open my_file
export doc as formatted text to alias (my_path & ".rtfd" as POSIX file)
close doc
end tell
end repeat
Now I need to find a way to get all POSIX path of files in folder...
Nothing worse than debugging applescript...
Maybe something like this would work?
set folderChoice to POSIX path of (choose folder)
tell application "System Events"
set myPaths to POSIX path of disk items of folder folderChoice
end tell
repeat with myPath in myPaths
<existing working code>
end repeat
Your code worked..up to a point: Pages stopped running the script when it hit the menacing “.DS_Store”
I hard coded the folder and managed to do the same as your code: (with the same error)
tell application "System Events"
set TitleList to POSIX path of items of folder "/Users/.../Documents/.../Client 1/"
end tell
set my_paths to result
repeat with my_path in my_paths
tell application "Pages"
set my_file to (my_path as POSIX file)
set my_name to name of (info for my_file)
set doc to open my_file
export doc as formatted text to alias (my_path & ".rtfd" as POSIX file)
close doc
end tell
end repeat
I saw a post where someone suggested only showing visibleFiles but I don't know how to integrate this into the existing code..
set TitleList to POSIX path of "/Users/.../Client 1/"
tell application "System Events"
set allVisibleFiles to files of folder TitleList whose visible is true
end tell
The result excludes the .DS_Store file but the list is not POSIX, rather it is: {file "Macintosh HD:Users:..:Client 1:Test_3.doc" of application "System Events", file...etc.}
I GOT IT!!!! WOOOHOOO! So Stoked!
set folderChoice to POSIX path of (choose folder)
tell application "System Events"
set allVisibleFiles to POSIX path of disk items of folder folderChoice whose visible is true
end tell
repeat with my_path in allVisibleFiles
tell application "Pages"
set my_file to (my_path as POSIX file)
set my_name to name of (info for my_file)
set doc to open my_file
export doc as formatted text to alias (my_path & ".rtfd" as POSIX file)
close doc
end tell
end repeat
Thank you David for your valuable input! Doing cartwheels in my living room LOL!!!
Congrats! Nice hacking!
I have a possible work around where finder get items of (choose folder) and then set my_paths to {items}, however AppleScript is saying that 'it can't get all the items'.
any ideas...