Saturday, July 22, 2017

#26 2017-01-11 03:19:02 pm

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

Re: Apple Script to move files no longer works in Sierra (Help)

I apologizes but I have absolutely no practice of networks and so  have no idea of what may fail.
Here is the code in which I added several say instructions.
Save it as an application and make tests with it using the network scheme.
If you listen carefully I hope that you will be able to discover which instruction has an odd behavior.

Applescript:

-- added height say instructions to trace the execution

set pathToApplicationSupport to path to application support from user domain as text # Edited according to StefanK's message
say "Point 1 .-.-.-." & pathToApplicationSupport
display dialog "Point 1 .-.-.-." & pathToApplicationSupport # ADDED
tell application "Finder"
   --set folderName to "folder name here" as text # DISABLED
   set successFlag to 0
   --set thisFolder to (target of front Finder window) as alias
   --set thisFolder to POSIX path of ((container of (path to me)) as text)
   set thisFolder to ((container of (path to me)) as alias)
   tell me to say "Point 2 .-.-.-." & (thisFolder as text)
   display dialog "Point 2 .-.-.-." & (thisFolder as text) # ADDED
   set folderName to name of thisFolder # ADDED
   tell me to say "Point 3 .-.-.-." & folderName
   display dialog "Point 3 .-.-.-." & folderName # ADDED
   set theTargetFolder to (pathToApplicationSupport & "Lotus Notes Data:")
   tell me to say "Point 4 .-.-.-." & theTargetFolder
   display dialog "Point 4 .-.-.-." & theTargetFolder # ADDED
   set theCourseFolder to (pathToApplicationSupport & "Lotus Notes Data:" & folderName)
   tell me to say "Point 5 .-.-.-." & theCourseFolder
   display dialog "Point 5 .-.-.-." & theCourseFolder # ADDED
   
   if (exists folder theTargetFolder) is false then
       set theTargetFolder to (pathToApplicationSupport & "IBM Notes Data:")
       tell me to say "Point 6 .-.-.-." & theTargetFolder
       display dialog "Point 6 .-.-.-." & theTargetFolder # ADDED
       set theCourseFolder to (pathToApplicationSupport & "IBM Notes Data:" & folderName)
       tell me to say "Point 7 .-.-.-." & theCourseFolder
       display dialog "Point 7 .-.-.-." & theCourseFolder # ADDED
   end if
   
   set filesToMove to (every file of thisFolder whose name extension is "nsf")
   
   if (exists folder theCourseFolder) is false then
       tell me to say "Point 8, must create the folder : " & folderName
       display dialog "Point 8, must create the folder : " & folderName # ADDED
       make new folder at theTargetFolder with properties {name:folderName}
   end if
   
   try
       move filesToMove to theCourseFolder
   on error
       display dialog "File(s) already exist. Do you wish to overwrite?" buttons {"Yes", "No"}
       if the button returned of the result is "Yes" then
           move filesToMove to theCourseFolder with replacing
       else
           set successFlag to 1
       end if
       
   end try
   
   if successFlag = 0 then
       display dialog "File(s) moved successfully." buttons {"OK"}
   else
       display dialog "File(s) not moved." buttons {"OK"}
   end if
   
end tell

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) mercredi 11 janvier 2017 21:16:46

Last edited by Yvan Koenig (2017-01-11 04:41:40 pm)

Offline

 

#27 2017-01-11 03:51:26 pm

myztklkev
Member
Registered: 2017-01-05
Posts: 13

Re: Apple Script to move files no longer works in Sierra (Help)

Yvan Koenig wrote:

I apologizes but I have absolutely no practice of networks and so  have no idea of what may fail.
Here is the code in which I added several say instructions.
Save it as an application and make tests with it using the network scheme.
If you listen carefully I hope that you will be able to discover which instruction has an odd behavior.

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) mercredi 11 janvier 2017 21:16:46


Thanks, I'll give it a try but I feel like it's an Apple problem at this point. Not sure the say commands will help as the script runs "Successfully" even when it doesn't move the files. I tested it through firefox and safari and it's the same, but emailing the exact same zip file directly (not downloading it with a web browser but a mail client) it runs fine. So that says to me that behavior with the way the web browsers download the zips is the problem which sounds weird but that's what's happening.

Edit: when it doesn't move the files it just says Point 3 B, when I copy the click me out of the folder and back in and run it point 3 mentions something about a folder. So seems that's where it's failing. No idea how it's being affected by downloading from a browser though.

I think the explanation might be here: https://eclecticlight.co/2016/06/16/mac … -updaters/

Last edited by myztklkev (2017-01-11 04:10:55 pm)

Offline

 

#28 2017-01-11 04:39:45 pm

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

Re: Apple Script to move files no longer works in Sierra (Help)

You wrote that the script said Point 3 B means that it executed the instruction:
   set folderName to name of thisFolder
and that he got "B" as the name of the passed folder.
It means also that the instruction
  set theTargetFolder to (pathToApplicationSupport & "Lotus Notes Data:")
was not executed or failed.

I hoped that you would listen with sufficient care to write what accompanied "Point 1" and "Point 2" so that I may know if the script correctly extracted the values supposed to be stored in the variables pathToApplicationSupport (for Point 1) and thisFolder (for Point 2)

I added 8 instructions supposed to display the text which is said just before.
Please make a test after saving this new version of the script posted in my preceding message.
When one dialog will appear, take a screenshot of this dialog then click the button OK.
Last not least, type in a new message the exact text displayed by each dialog.

Normally you would get  something like
"Point 1 .-.-.-.HardDiskName:Users:yourHome:Library:Application Support:"
"Point 2 .-.-.-.the path to the folder containing the script and the nsf files:"
"Point 3 .-.-.-.the name of the folder containing the script and the nsf files"
"Point 4 .-.-.-.HardDiskName:Users:yourHome:Library:Application Support:Lotus Notes Data:"
"Point 5 .-.-.-.HardDiskName:Users:yourHome:Library:Application Support:Lotus Notes Data:" completed by the name of the folder containing the script and the nsf files

For me it's time to switch off, I will be back tomorrow.

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) mercredi 11 janvier 2017 22:38:53

Offline

 

#29 2017-01-11 08:12:52 pm

myztklkev
Member
Registered: 2017-01-05
Posts: 13

Re: Apple Script to move files no longer works in Sierra (Help)

Yvan Koenig wrote:

I hoped that you would listen with sufficient care to write what accompanied "Point 1" and "Point 2" so that I may know if the script correctly extracted the values supposed to be stored in the variables pathToApplicationSupport (for Point 1) and thisFolder (for Point 2)


It was saying way to much for me understand it all clearly, let alone to write it down. Point 2 was just a bunch of random numbers and letters it sounded like. I just ran the script under both working and not working conditions and listened for differences. Point 3 was the only one I noticed that sounded different in not working conditions which is why I only mentioned it. I assume 1 and 2 ran correctly as it sounded the same when I ran the script under working conditions

Your explanation about it failing though sounds very similar to that link I posted explaining that gatekeeper is the culprit.

I'll try your one with prompts tomorrow.

Last edited by myztklkev (2017-01-11 08:22:39 pm)

Offline

 

#30 2017-01-12 09:21:45 am

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

Re: Apple Script to move files no longer works in Sierra (Help)

Assuming that the problem is really linked to GateKeeper, here is an alternate scheme.

No need to put an application in the archived folder.
Distribute to your correspondants the script below saved as an application.
When they will receive your zipped folder, they will no longer have to double click it to expand it then double click an enclosed application.
They will just have to drag & drop the archive onto the new application.
This one will expand the archive and move the enclosed nsf files.
As this new scheme doesn't rely upon an app enclosed in the expanded archive I assume that there will be no problem with GateKeeper.

Applescript:

(*
Save this script as an application.
Drag and drop a zip archive on it.
It will expand the archive then move the enclosed nsf files to their required location.

KOENIG Yvan (VALLAURIS, France)
2016/01/12
*)


on run
   # Entry point used if you double click the application's icon
   my germaine(choose file with prompt "Choose a zip archive" of type "zip")
end run

on open sel
   # Entry point used if you drop a zip file on the application's icon
   set maybe to sel's item 1
   tell application "Finder"
       if name extension of maybe is not "zip" then error "The dropped item must be a zip archive!"
   end tell
   my germaine(maybe)
end open


on germaine(theZip)
   # Get the path to the folder containing the dropped archive
   tell application "Finder"
       set archiveContainer to container of theZip as alias
   end tell
   
   set quotedPOSIXZip to quoted form of POSIX path of theZip
   set quotedPOSIXarchiveContainer to quoted form of POSIX path of archiveContainer
   # Expand the archive in it's own container (Thank's to Shane STANLEY)
   do shell script ("ditto -xk " & quotedPOSIXZip & space & quotedPOSIXarchiveContainer)
   set pathToApplicationSupport to path to application support from user domain as text
   # Build the path of the expanded folder
   set thisFolder to (text 1 thru -5 of (theZip as text)) as alias
   tell application "Finder"
       set successFlag to 0
       set folderName to name of thisFolder
       set theTargetFolder to (pathToApplicationSupport & "Lotus Notes Data:")
       set theCourseFolder to (pathToApplicationSupport & "Lotus Notes Data:" & folderName)
       
       if not (exists folder theTargetFolder) then
           set theTargetFolder to (pathToApplicationSupport & "IBM Notes Data:")
           set theCourseFolder to (pathToApplicationSupport & "IBM Notes Data:" & folderName)
       end if
       
       set filesToMove to (every file of thisFolder whose name extension is "nsf")
       
       if not (exists folder theCourseFolder) then
           make new folder at theTargetFolder with properties {name:folderName}
       end if
       
       try
           move filesToMove to theCourseFolder
       on error
           display dialog "File(s) already exist. Do you wish to overwrite?" buttons {"Yes", "No"}
           if the button returned of the result is "Yes" then
               move filesToMove to theCourseFolder with replacing
           else
               set successFlag to 1
           end if
           
       end try
       
       if successFlag = 0 then
           display dialog "File(s) moved successfully." buttons {"OK"}
       else
           display dialog "File(s) not moved." buttons {"OK"}
       end if
   end tell
end germaine

Here is an alternate version. I wrote it because, as I have no practice of networks I'm not sure that the ditto instruction would behave correctly.
With this version, the archive is expanded in the temporary folder which is on the local machine so I know that the process works.

Applescript:

(*
Save this script as an application.
Drag and drop a zip archive on it.
It will expand the archive then move the enclosed nsf files to their required location.

KOENIG Yvan (VALLAURIS, France)
2016/01/12
*)


on run
   # Entry point used if you double click the application's icon
   my germaine(choose file with prompt "Choose a zip archive" of type "zip")
end run

on open sel
   # Entry point use if you drop a zip file on the application's icon
   set maybe to sel's item 1
   tell application "Finder"
       if name extension of maybe is not "zip" then error "The dropped item must be a zip archive!"
   end tell
   my germaine(maybe)
end open


on germaine(theZip)
   tell application "Finder"
       set archiveName to name of theZip
   end tell
   
   set quotedPOSIXZip to quoted form of POSIX path of theZip
   # Set the path to the folder containing the dropped archive
   set path2Temp to path to temporary items as text # this path ends with a colon
   set quotedPOSIXarchiveContainer to quoted form of POSIX path of path2Temp
   # Expand the archive in the temporary items folder (Thank's to Shane STANLEY)
   do shell script ("ditto -xk " & quotedPOSIXZip & space & quotedPOSIXarchiveContainer)
   # Build the path of the expanded folder
   set folderName to text 1 thru -5 of archiveName # archive name deprieved of the name extension
   set thisFolder to (path2Temp & folderName) as alias

   set pathToApplicationSupport to path to application support from user domain as text # this path ends with a colon
   tell application "Finder"
       set successFlag to 0
       set theTargetFolder to (pathToApplicationSupport & "Lotus Notes Data:")
       set theCourseFolder to (pathToApplicationSupport & "Lotus Notes Data:" & folderName)
       
       if not (exists folder theTargetFolder) then
           set theTargetFolder to (pathToApplicationSupport & "IBM Notes Data:")
           set theCourseFolder to (pathToApplicationSupport & "IBM Notes Data:" & folderName)
       end if
       
       set filesToMove to (every file of thisFolder whose name extension is "nsf")
       
       if not (exists folder theCourseFolder) then
           make new folder at theTargetFolder with properties {name:folderName}
       end if
       
       try
           move filesToMove to theCourseFolder
       on error
           display dialog "File(s) already exist. Do you wish to overwrite?" buttons {"Yes", "No"}
           if the button returned of the result is "Yes" then
               move filesToMove to theCourseFolder with replacing
           else
               set successFlag to 1
           end if
           
       end try
       
       if successFlag = 0 then
           display dialog "File(s) moved successfully." buttons {"OK"}
       else
           display dialog "File(s) not moved." buttons {"OK"}
       end if
   end tell
end germaine

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) jeudi 12 janvier 2017 15:20:06

Last edited by Yvan Koenig (2017-01-12 12:06:48 pm)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)