OO3: Workaround for scripting save as bug

Timothy J.Wood tjw at omnigroup.com
Thu Dec 2 15:01:46 PST 2004



   I believe this is a bug in Cocoa's AppleScript support.  We already 
have logged a bug with Apple that they standardize on ONE path 
representation in AppleScript (I really don't care which at this point! 
:).

   The 'chose file name' is going to return a HFS+ path (':' delimited 
with volume name) while OO3 requires POSIX paths since it is written in 
Cocoa.

   I haven't tried it, but I strongly suspect you'd see this same bug 
with TextEdit.

-tim


On Sunday, November 28, 2004, at 03:27  PM, mentorsw wrote:

> For those working with scripting the OO3 beta, there is a bug related 
> to
> doing the equivalent of a Save As... on a document. [NOTE to OmniGroup:
> Bug report to follow] The following script fails:
>
> tell application "OmniOutliner Pro3B3"
> 	activate
> 	
> 	-- make a new document
> 	make new document at the end of documents
> 	set newDocument to front document
> 	
> 	--make a new row
> 	make new row at end of rows of newDocument
> 	set theRow to last row of newDocument
> 	set text of cell 2 of theRow to "Testing..."
> 	
> 	set newFile to choose file name
> 	
> 	tell newDocument
> 		try
> 			save in newFile
> 		on error errormessage number errornumber from offendingObject
> 			display dialog errormessage buttons {"OK"} default button 1
> 		end try
> 	end tell
> end tell
>
>
> The workaround:
>
> MakeANewDocument()
> activate
> set newFile to choose file name
> DoSaveAs(newFile)
>
> on DoSaveAs(newFile)
> 	-- get filename
> 	set newFilePOSIXPath to POSIX path of newFile as Unicode text
> 	set oldDelims to AppleScript's text item delimiters
> 	set AppleScript's text item delimiters to {"/"}
> 	set newFileName to last text item of newFilePOSIXPath
> 	set AppleScript's text item delimiters to oldDelims
> 	
> 	-- Add extension if necessary
> 	if newFileName does not end with ".oo3" then
> 		set newFileName to newFileName & ".oo3"
> 		set newFilePOSIXPath to newFilePOSIXPath & ".oo3"
> 	end if
> 	set newFile to POSIX file newFilePOSIXPath
> 	
> 	tell application "OmniOutliner Pro3B3"
> 		activate
> 		set newDocument to front document
> 		try
> 			save newDocument as "OmniOutliner 3" in newFile
> 		on error errormessage number errornumber from offendingObject
> 			display dialog errormessage buttons {"OK"} default button 1
> 		end try
> 	end tell
> end DoSaveAs
>
> on MakeANewDocument()
> 	tell application "OmniOutliner Pro3B3"
> 		activate
> 		
> 		-- make a new document
> 		make new document at the end of documents
> 		set newDocument to front document
> 		
> 		--make a new row
> 		make new row at end of rows of newDocument
> 		set theRow to last row of newDocument
> 		set text of cell 2 of theRow to "Testing..."
> 	end tell
> end MakeANewDocument
>
>
>
> ____________________
> David Amis
> Mentor Software,Inc.
> Atlanta, GA
> (404) 228-4640
>
>
> _______________________________________________
> OmniOutliner-Users mailing list
> OmniOutliner-Users at omnigroup.com
> http://www.omnigroup.com/mailman/listinfo/omnioutliner-users
>




More information about the OmniOutliner-Users mailing list