Friday, March 24, 2017

#1 2016-12-18 03:50:18 pm

kamel3d
Member
From: London
Registered: 2016-10-03
Posts: 22

applescript comunication with ASOC

Hi guys,
I have and number of AppleScripts running on network machines and I am trying to make them write data in one single file and the data get read by an Applescriptobjc app running on a server, I tried to write to text file but for some reason, the scripts could not write to  the file on the network, so my other option is to write to an SCPT file on the network (I have not tried yet), for now it seem complicated for ASOC app to read from this file, and it gives me all kind of errors when trying to put the file inside the app, so my questions are:
1- is there a was for  ASOC  to read SCPT files
2- is there a better way to make  AppleScripts  app and ASOC  communicate well?

Thank you guys

Kamel

Offline

 

#2 2016-12-18 05:38:29 pm

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

Re: applescript comunication with ASOC

kamel3d wrote:

I am trying to make them write data in one single file

Don't -- have them write separate files. Changing from text to .scpt would only make the problem worse.


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

Offline

 

#3 2016-12-18 06:00:33 pm

kamel3d
Member
From: London
Registered: 2016-10-03
Posts: 22

Re: applescript comunication with ASOC

I am having a problem writing text files to the network, it works fine on local computer, but it seem to have a problem with permissions even though I have full access to it
any idea?

Offline

 

#4 2016-12-18 06:10:12 pm

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

Re: applescript comunication with ASOC

kamel3d wrote:

I am having a problem writing text files to the network, it works fine on local computer, but it seem to have a problem with permissions even though I have full access to it
any idea?

No. But whatever it is, changing file types is unlikely to solve the problem.


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

Offline

 

#5 2016-12-18 06:16:04 pm

kamel3d
Member
From: London
Registered: 2016-10-03
Posts: 22

Re: applescript comunication with ASOC

sad

Offline

 

#6 2016-12-18 06:25:23 pm

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

Re: applescript comunication with ASOC

You could always post your code here, and the error you're receiving...


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

Offline

 

#7 2016-12-18 07:01:48 pm

kamel3d
Member
From: London
Registered: 2016-10-03
Posts: 22

Re: applescript comunication with ASOC

here is my code, I am testing it now at home and it works fine, but at work it dos not, also I should mention I have an ASOC app that writes to a text file on the network and it works fine, but this one don't

Applescript:

property logFilePath : "/Volumes/home/admin/NAS/temp/MACHINESLOG.txt"
my updateLog("GFX1", "Desktop Cleaned")

on updateLog(PCName, task)
   set dd to getToday()
   set logline to PCName & " " & task & " " & dd
try
   set thePath to logFilePath
   set thePath to POSIX path of thePath
   set textFile to (open for access POSIX file thePath with write permission)
   get eof textFile
   set oldText to read textFile
   set eof textFile to 0
   write logline & return & oldText to textFile -- I reverted this so it write the new line on the top
   close access textFile
end try
end updateLog

on getToday() -- here I construct todays date
   set dw to weekday of (current date)
   set dd to day of (current date) -- get the day
   if dd < 10 then
       set dd to "0" & dd as string -- add zero if the number is less than 10
   end if
   set mm to month of (current date) -- get month
   if mm < 10 then
       set mm to "0" & mm * 1 as string -- *1 is to transform the word of the month to number
   else
       set mm to mm * 1
   end if
   set yy to year of (current date) -- get the year
   set tt to time string of (current date)
   set numiricDate to dw & " " & dd & "-" & mm & "-" & yy & " " & tt & " " as string
   return numiricDate
end getToday

Offline

 

#8 2016-12-18 07:04:21 pm

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

Re: applescript comunication with ASOC

Start by adding an "on error..." section to track exactly what the error is.


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

Offline

 

#9 2016-12-18 07:16:44 pm

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

Re: applescript comunication with ASOC

Also, that getToday handler isn't very attractive. You're calling current date multiple times, among other things. You're using ASObjC, so you might as well use the tools designed for this sort of thing:

Applescript:

set theDate to current application's NSDate's |date|()
set df to current application's NSDateFormatter's new()
df's setDateFormat:"EEEE yyyy-MM-dd hh:mm:ss a"
(df's stringFromDate:theDate) as text


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

Offline

 

#10 2016-12-20 08:52:17 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2589

Re: applescript comunication with ASOC

What file sharing protocol are you using? A file can only be written once at the same time by the kernel and locally it work perfect. When opening a file over network with write privileges becomes more complex because the virtual file systems needs to ask the server if the file is available for write or not. Different protocols uses their own methods and with smb you can even choose different kind of locking.

Easiest way to do this is writing atomically to the file. Write local file first and when done copy to network volume. So when read and writing to the file you're actually working with a local copy. You could also use a lock file where you indicate which service and program is currently owns permission to the file so other scripts will wait for the script to be finished.

Online

 

#11 2016-12-21 09:04:07 am

kamel3d
Member
From: London
Registered: 2016-10-03
Posts: 22

Re: applescript comunication with ASOC

DJ Bazzie Wazzie wrote:

What file sharing protocol are you using?

connected using NFS, don't know if that tells you something... 

Shane here the errors I am getting

Applescript:

error "File file graphics:SYSTEM FILES:MACHINESLOG.txt is already open." number -49 from file "graphics:SYSTEM FILES:MACHINESLOG.txt"

and this one too
https://dl.dropboxusercontent.com/u/6735961/error.jpg

Last edited by kamel3d (2016-12-21 03:00:58 pm)

Offline

 

#12 2016-12-21 06:14:08 pm

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

Re: applescript comunication with ASOC

That means that whatever last opened it with read access hasn't closed it. You need to make sure you do that -- writing atomically as DJ suggested is probably bast. Post your file writing code...


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

Offline

 

#13 2016-12-22 02:13:58 pm

kamel3d
Member
From: London
Registered: 2016-10-03
Posts: 22

Re: applescript comunication with ASOC

Thank you Shane, yes I already started making that way it seem more reliable.

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.047 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)