Friday, December 15, 2017

#1 2016-06-23 04:45:23 am

SunnyFrinton
Member
Registered: 2012-09-13
Posts: 19

Amend record in csv file using ApplescriptObjC

I have an script which works in Applescript but when I use the same code in an ASOC script it does not. Any amended record is added to the middle of another existing record and does not replace the intended record. I have tried every combination of text items/paragraphs etc but nothing works so a solution wold be very gratefully received.

  set theNumber to memberNumber's stringValue() as text -- Coerce Cocoa text to Applescript text
  set theFamily to memberFamily's stringValue() as text
  set theTitle to memberTitle's stringValue() as text
  set theInitials to memberInitials's stringValue() as text
  set theSurname to memberSurname's stringValue() as text
  set theAddress1 to memberAddress1's stringValue() as text
  set theAddress2 to memberAddress2's stringValue() as text
  set theAddress3 to memberAddress3's stringValue() as text
  set theAddress4 to memberAddress4's stringValue() as text
  --
        set amendedRecord to  theNumber & "," & ¬
                theFamily & "," & ¬
                theTitle & "," & ¬
                theInitials & "," & ¬
                theSurname & "," & ¬
                theAddress1 & "," & ¬
                theAddress2 & "," & ¬
                theAddress3 & "," & ¬
                theAddress4
            --
            set fileReference to read "/Users/Ours/Documents/Cats Protection/Membership/CP Members copy.csv" as «class utf8»
            set text item delimiters to return
            set recordList to text items of fileReference
            set item theSel of recordList to amendedRecord
            set fileReference to open for access "/Users/Ours/Documents/Cats Protection/Membership/CP Members copy.csv" with write permission
            set eof fileReference to 0
            write (recordList as text) to fileReference as «class utf8»
            close access fileReference

Offline

 

#2 2016-06-23 06:34:19 am

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

Re: Amend record in csv file using ApplescriptObjC

Wrap the read/open/write/close commands in  "tell current application" blocks.


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

Offline

 

#3 2016-06-23 08:43:43 am

SunnyFrinton
Member
Registered: 2012-09-13
Posts: 19

Re: Amend record in csv file using ApplescriptObjC

Used "System Events" as the current application and it now works perfectly so thanks for saving my sanity!!
So why does it work in Applescript but not in ASOC?

Offline

 

#4 2016-06-23 09:35:45 am

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

Re: Amend record in csv file using ApplescriptObjC

SunnyFrinton wrote:

So why does it work in Applescript but not in ASOC?


AppleScript can't actually read or write; the commands have to be passed to the host application (Script Editor, the applet, whatever). But in an ASObjC app built in Xcode, the concept of a host application works differently.


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

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)