Omni
2006-04-13, 06:03 AM
Quote:
Originally Posted by af3556
Alas, I can't find any such functionality in the current OmniGraffle - am I asking too much?
|
Hi Ben,
This isn't available built-in to OmniGraffle itself, but it is possible to do it via Graffle's AppleScript support. In fact, it made for a nice little scripting project last night. Just paste the following into Script Editor, and follow the instructions.
Code:
-- Here is an AppleScript that will watch a folder for changes to Graffle files and automatically convert them to another format. Before use you should:
-- 1. Change the properties at the beginning to match the behavior you would like as far as where to watch and what type to export as.
-- 2. Towards the bottom there is a "here is where you set the export settings" section where you can do the AppleScript equivalent of setting various controls on Graffle's export panel. You may want to change the export settings here. See Graffle's AppleScript dictionary for details on the setting names, and et cetera.
-- 3. Finally, you may also need to change the application name from "OmniGraffle Professional" to just "OmniGraffle" in process_item if you have the standard version instead of pro.
-- Then just run the script. It will keep running forever until you manually stop it. You could set it up as a startup item if desired.
-- a file extension which Graffle supports for export
property new_extension : "png"
-- the folder to watch
property watch_folder : "Macintosh HD:Users:toon:Desktop"
-- the subfolder inside the watch folder where the exported documents should go
property export_foldername : "Images"
-- amount of time to wait in between checking for file changes
property seconds_between_checks : 30
tell application "Finder"
-- set up the watch folder and create the export folder inside
tell application "Finder"
set watch_folder to watch_folder as alias
if not (exists folder export_foldername of watch_folder) then
make new folder at watch_folder with properties {name:export_foldername}
end if
set the export_folder to (folder export_foldername of watch_folder) as alias
end tell
-- repeat forever
repeat
-- get all the graffle files in the watch folder
set fileList to files of watch_folder whose kind is "OmniGraffle document"
repeat with aFile in fileList
-- figure out what the new exported name would be
set new_name to my rename(aFile, new_extension)
set the target_path to (((export_folder as string) & new_name) as string)
-- if there isn't an export file or if the graffle file is newer, do the export
if (not (exists document file new_name of export_folder)) or modification date of aFile > modification date of document file new_name of export_folder then
my process_item(aFile as alias, new_name, export_folder)
end if
end repeat
-- wait before we look again
delay seconds_between_checks
end repeat
end tell
-- this sub-routine just comes up with the new name
on rename(this_item, new_extension)
tell application "Finder"
set the file_name to the name of this_item
set file_extension to the name extension of this_item
if the file_extension is "" then
set the trimmed_name to the file_name
else
set the trimmed_name to text 1 thru -((length of file_extension) + 2) of the file_name
end if
set target_name to (the trimmed_name & "." & new_extension) as string
end tell
return the target_name
end rename
-- this sub-routine does the export
on process_item(source_file, new_name, results_folder)
set the source_item to the POSIX path of the source_file
set the target_path to (((results_folder as string) & new_name) as string)
with timeout of 900 seconds
tell application "OmniGraffle Professional"
-- save the current export settings so we can replace them later
set oldAreaType to area type of current export settings
set oldBorder to include border of current export settings
-- here is where you set the export settings you want
set area type of current export settings to all graphics
set include border of current export settings to true
-- open the file if it isn't already open
set needToOpen to (count (documents whose path is source_item)) is 0
if needToOpen then
open source_file
end if
-- do the export
set docsWithPath to documents whose path is source_item
set theDoc to first item of docsWithPath
save theDoc in file target_path
-- if the file wasn't already open, close it again
if needToOpen then
close theDoc
end if
-- put the original export settings back
set area type of current export settings to oldAreaType
set include border of current export settings to oldBorder
end tell
end timeout
end process_item
Last edited by Greg Titus; 2006-04-13 at 06:07 AM..