Last active
December 7, 2016 19:56
-
-
Save codemonkey-uk/d8a0f82255f7f42068c2dccdd7ddb57f to your computer and use it in GitHub Desktop.
Apple Script to convert old Documents to RTF using iWork '08 Pages.app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
property PagesApp : ((path to applications folder) as text) & "iWork '08:" & "Pages.app:" | |
on open theDroppedItems | |
repeat with a from 1 to count of theDroppedItems | |
set theCurrentItem to item a of theDroppedItems | |
tell application "Finder" | |
set isFolder to folder (theCurrentItem as string) exists | |
end tell | |
-- Process a dropped folder | |
if isFolder = true then | |
processFolder(theCurrentItem) | |
-- Process a dropped file | |
else | |
processFile(theCurrentItem) | |
end if | |
end repeat | |
end open | |
on processFolder(theFolder) | |
-- NOTE: The variable theFolder is a folder reference in AppleScript alias format | |
-- Retrieve a list of any visible items in the folder | |
set theFolderItems to list folder theFolder without invisibles | |
-- Loop through the visible folder items | |
repeat with a from 1 to count of theFolderItems | |
set theCurrentItem to ((theFolder as string) & (item a of theFolderItems)) as alias | |
open {theCurrentItem} | |
end repeat | |
-- Add additional folder processing code here | |
end processFolder | |
on processFile(aFile) | |
tell application PagesApp | |
try | |
open aFile | |
set fullpath to POSIX path of aFile as string | |
set endc to (length of fullpath) - (offset of "/" in (reverse of text items of fullpath as string)) | |
set parentpath to text 1 thru endc of fullpath | |
tell application "System Events" | |
tell process "Pages" | |
activate | |
set frontmost to true | |
click menu item "Export…" of menu 1 of menu bar item "File" of menu bar 1 | |
click radio button "RTF" of radio group of sheet 1 of window 1 | |
click button "Next..." of sheet 1 of window 1 | |
keystroke parentpath | |
key code 36 | |
click button "Export" of sheet 1 of window 1 | |
end tell | |
end tell | |
close front document saving no | |
end try | |
end tell | |
end processFile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment