Friday, December 15, 2017

#1 2016-11-22 11:52:38 am

t524ube
Member
Registered: 2009-09-29
Posts: 156

Write date to a file

Hi,

I am  trying to save data from a textView using  Shane Stanley's showSavePane: from Myriad Helper 20.2.  The code works when using appleScript's choose file name, however, it doesn't open the dropdown sheet when I put the following code:

Property parent : class "NSObject"
property theWindow : missing value
property textView : missing value

     on showSavePanel:sender
          set thePanel to current application's NSSavePanel's makeSaveAt:(path to desktop folder) |types|:{"txt"} |name|:"Some output" prompt:"Save Some Information Text:" title:"My Save Title"
               
          set theText to textView's textStorage()'s |string|() as text ## this is in NSUTF8StringEncoding: format
          set fileManager to current application's NSFileManager's defaultManager()
   
            if (fileManager's fileExistsAtPath:thePanel) as boolean = false then
             set theResult to fileManager's createFileAtPath:thePanel |contents|:theText attributes:(missing value)
          end if

           thePanel's showOver:theWindow calling:{"saveSheetDone:", me}
    end showSavePanel:
   
    on saveSheetDone:theResult -- called when panel closed
        if theResult = missing value then
            -- cancel button
            log "Cancel pressed"
            else
            log theResult -- path to file
        end if
    end saveSheetDone:

Could I get some assistance to get the above working. Just a note here, I have not been doing any ASOC scripting for over two years so I have forgotten quite a bit.

Thanks,
t.

Last edited by t524ube (2016-11-22 12:41:19 pm)

Offline

 

#2 2016-11-22 05:38:12 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: Write date to a file

You're using thePanel as if it's a path. You need to get a path. You're also writing the file incorrectly. Try something like this:

Applescript:

set theText to textView's textStorage()'s |string|()
set thePath to thePanel's |URL|()'s |path|()

if (fileManager's fileExistsAtPath:thePanel) as boolean = false then
   theText's writeToFile:thePath atomically:true encoding:(current application's NSUTF8StringEncoding) |error|:(missing value)
end if


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2016-11-22 08:22:50 pm

t524ube
Member
Registered: 2009-09-29
Posts: 156

Re: Write date to a file

Thank you Shane this works.

Thanks,
t.

Last edited by t524ube (2016-11-23 09:08:27 am)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)