Monday, December 11, 2017

#1 2009-10-16 12:23:05 pm

Heiner
Member
From:: Germany
Registered: 2007-08-25
Posts: 147

From pasteboard to table view column

Hi,

all things are from beginning now!

One (of a lot of) problem(s) for me is how to manage in ASOC to set a list (i.e. a list of names) into a table view's column.
The" old" AS-method:
set thecontent to contents of pasteboard "general", etc. doesn't operate obviously.

Greetings
Heiner


Filed under: pasteboard

Offline

 

#2 2009-10-16 05:40:40 pm

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

Re: From pasteboard to table view column

Depending on what you're trying to achieve, you may do best to use bindings.


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

Offline

 

#3 2009-10-17 05:44:20 am

Heiner
Member
From:: Germany
Registered: 2007-08-25
Posts: 147

Re: From pasteboard to table view column

Hi Shane,
thanks for your reply;

my first problem is to get access to the pasteboard itself. I had a look in the documentation. There I found that NSPasteboard is inherited from NSObject (so far so good), but I can't 'tanslate' ObjC to ASOC yet. What I need is a basic sample how to use a pasteboard. I add the handler (in ASS) which I have to replace.

Applescript:


on setNames() -- a handler in ASStudio
   set oldTextItemDelimiters to AppleScript's text item delimiters
   set AppleScript's text item delimiters to return
   set preferred type of pasteboard "general" to "string"
   
   if pasteboard "general" is not "" then
       try
           set theContents to contents of pasteboard "general"
           set theCount to (count of text items of theContents)
           if last text item of theContents is "" then -- a return after last name
               set theCount to theCount - 1
           end if
           set update views of myDataSource to false
           repeat with n from 1 to theCount
               set theDataRow to make new data row at the end of data rows of myDataSource
               set contents of data cell "name" of theDataRow to text item n of theContents
           end repeat
           set update views of myDataSource to true
           set modified of document of window "main" to true
       on error
           display alert "Error!" message "Pasteboard is empty." as critical default button "OK" attached to window "main"
       end try
   end if
   set AppleScript's text item delimiters to oldTextItemDelimiters
end setNames

Thanks in advance

Heiner

PS: I have examined your example 'Coming to Florida'. Thanks for that example!

Last edited by Heiner (2009-10-17 05:48:34 am)

Offline

 

#4 2009-10-18 04:58:46 am

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

Re: From pasteboard to table view column

You might think about using AS to get the clipboard -- it's simpler than pasteboards. Then, if you have the contents bound to a variable, you can set the value of the variable to the contents of the clipboard as a list.


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

Offline

 

#5 2009-10-18 07:15:51 am

Heiner
Member
From:: Germany
Registered: 2007-08-25
Posts: 147

Re: From pasteboard to table view column

Thank you Shane!

I got it and that's my solution:

Applescript:


property parent : class "NSObject"
   
   property theData : missing value
   
   property theName : ""
   
   
   -- IB Actions (button clicks)
   on setNames_(sender)
       try
           set theContents to the clipboard as string
       end try
       set oldTextItemDelimiters to AppleScript's text item delimiters
       set AppleScript's text item delimiters to return
       set theCount to (count text items of theContents)
       repeat with i from theCount to 1 by -1 -- otherwise it's in inverse direction; ('first in, last out' ?)
           set my theData to {{theName:text item i of theContents, nr1:"", nr2:"", nr3:"", sum:""}} & my theData
       end repeat
       set AppleScript's text item delimiters to oldTextItemDelimiters
   end setNames_
   
   ##########################
   -- Application
   
   on awakeFromNib()
       set my theData to {{theName:"", nr1:"", nr2:"", nr3:"", sum:""}} -- it seems to be necessarily (otherwise the app hangs; but I get an empty line in the table view
   end awakeFromNib
   

Maybe there is a better solution. I'm very interested in that.

Heiner

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)