Wednesday, March 29, 2017

#1 2017-01-02 07:57:29 am

Hirsute
Member
Registered: 2017-01-02
Posts: 1

read/write permissions failing for a folder created by apple script

The following has worked, something changed on my macbook and now it doesn't anymore.  Any help would be appreciated.
The script creates two folders with next Sunday's date, opens a MSWord template and saves a copy in each folder. Supposedly! It appears to be something to do with apple script not having the permissions to create the new files in the folders it has just created.  If I run the program live (whilst I am sitting watching it) it asks me to grant permission for the folder access.


Applescript:


set d to current date
repeat
   set w to (weekday of d) as number
   if w = 1 then exit repeat
   set d to d + (1 * days)
end repeat
d
set dayname to {day} of d as string
set monthname to {month} of d
dayname & monthname as string
set the_date to dayname & monthname as string


tell application "Finder"
   activate
   open home
   set target of Finder window 1 to folder "lbc services joint folder" of folder "Dropbox" of folder "Iona" of folder "Users" of startup disk
   make new folder at folder "lbc services joint folder" of folder "Dropbox" of folder "Iona" of folder "Users" of startup disk with properties {name:dayname & monthname}
end tell


say "done first one"
set pm to "PM"
tell application "Finder"
   activate
   set target of Finder window 1 to folder "lbc services joint folder" of folder "Dropbox" of folder "Iona" of folder "Users" of startup disk
   make new folder at folder "lbc services joint folder" of folder "Dropbox" of folder "Iona" of folder "Users" of startup disk with properties {name:dayname & monthname & pm}
   close Finder window 1
end tell
say "I have created both folders as requested"

set mydoc to "/Users/iona/Dropbox/lbc services joint folder/Service Running Schedule - DO NOT DELETE!.dotx"
tell application "Microsoft Word"
   activate
   open mydoc
   save as active document file name "/Users/iona/Dropbox/lbc services joint folder/" & the_date & "/Service running schedule am1.docx"
   close active document
end tell

set mydoc to "/Users/iona/Dropbox/lbc services joint folder/Service Running Schedule - DO NOT DELETE!.dotx"
tell application "Microsoft Word"
   activate
   open mydoc
   save as active document file name "/Users/iona/Dropbox/lbc services joint folder/" & the_date & "/Service running schedule am2.docx"
   close active document
end tell

set mydoc to "/Users/iona/Dropbox/lbc services joint folder/Service Running Schedule - DO NOT DELETE!.dotx"
tell application "Microsoft Word"
   activate
   open mydoc
   save as active document file name "/Users/iona/Dropbox/lbc services joint folder/" & the_date & "pm/Service running schedule.docx"
   close active document
end tell
say "That is the files done too, closing down"

Offline

 

#2 2017-01-02 08:31:41 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 2882

Re: read/write permissions failing for a folder created by apple script

I don't own Word so I can't test but I assume that this cleaned script may do what is wanted.

Applescript:

set d to current date
repeat
   set w to (weekday of d) as number
   if w = 1 then exit repeat
   set d to d + (1 * days)
end repeat
d
set dayname to day of d as string # EDITED
set monthname to month of d # EDITED
--dayname & monthname as string # useless
set the_date to dayname & monthname # EDITED

set jointFolder to (path to home folder as text) & "Dropbox:lbc services joint folder"
tell application "Finder"
   activate
   --open home
   --set target of Finder window 1 to folder "lbc services joint folder" of folder "Dropbox" of folder "Iona" of folder "Users" of startup disk
   set dateFolder to (make new folder at folder jointFolder with properties {name:the_date}) as text # EDITED
   --end tell
   
   
   tell me to say "done first one"
   set pm to "PM"
   --tell application "Finder"
   --    activate
   --set target of Finder window 1 to folder "lbc services joint folder" of folder "Dropbox" of folder "Iona" of folder "Users" of startup disk
   set datePMFolder to (make new folder at folder jointFolder with properties {name:the_date & pm}) as text # EDITED
   --close Finder window 1 # useless
end tell
say "I have created both folders as requested"


set mydoc to POSIX path of (jointFolder & "Service Running Schedule - DO NOT DELETE!.dotx")
set newDoc1 to POSIX path of (dateFolder & "Service running schedule am1.docx")
set newDoc2 to POSIX path of (dateFolder & "Service running schedule am2.docx")
set newDoc3 to POSIX path of (datePMFolder & "Service running schedule.docx")

# I stopped testing here

tell application "Microsoft Word"
   activate
   open mydoc
   save as active document file name newDoc1
   save as active document file name newDoc2
   save as active document file name newDoc3
   close active document
end tell

say "That is the files done too, closing down"

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) lundi 2 janvier 2017 15:26:27

Last edited by Yvan Koenig (2017-01-02 08:38:10 am)

Offline

 

#3 2017-01-02 09:10:28 am

Nigel Garvey
Moderator
From: Warwickshire, England
Registered: 2002-11-19
Posts: 4225

Re: read/write permissions failing for a folder created by apple script

Hi. Welcome to MacScripter.

Not related to your problem, but if Yvan's modifications do the trick, another refinement would be this at the top of the script instead of the repeat:

Applescript:

set d to (current date)
set w to (weekday of d) as number
if (w > 1) then set d to d + (8 - w) * days
d


NG

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.103 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)