Hi,
After Updating to Jun 1, 2020, Security Update 2020-003 (High Sierra),
it is taking a considerably longer time than usual for Move, Copy commands (approx. 5 mins for 15-20 files avg. 2 MB files). These scripts were working fine before this update.
Script taking very long time to Move, Copy multiple files.
Single File Move, Copy works fine. Fresh/reinstall produces the same result
I appreciate a solution for this pattern move.
use AppleScript version “2.4” – Yosemite (10.10) or later
use scripting additions
tell application “Finder”
# long time delay on this block
# File Sample : Sub A_Data 001.jpg, Sub M2 A_Data Table 7.jpg, Sub 5 Q_Data 36.jpg, Sub Q_Data 63.jpg, Sub P4 Q_Data 02.jpg
set F_Answer to (“/Volumes/SSD_D2/Exam Data/Answer”) as POSIX file as alias
set F_Question to (“/Volumes/SSD_D2/Exam Data/Question”) as POSIX file as alias
set F_Source to (“/Volumes/SSD_D2/Exam Data/Source Data”) as POSIX file as alias
set Pattern_A to "A_Data"
set Pattern_Q to "Q_Data"
move (every file of folder F_Source whose name contains Pattern_A) to folder F_Answer
move (every file of folder F_Source whose name contains Pattern_Q) to folder F_Question
end tell
It seems useful to check the state of your device or the state of the files themselves.
With the same system updated the same,
I ran your script using a mechanical HD as a substitute of your “SSD_D2”
Source Data contained 22 files for a total of 21 Mbytes.
“That took 0.769198060036 seconds.”
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 29 juin 2020 18:37:31
Before posting I reverted to previous state (through time machine backup). Before the update everything same data / script worked very fast. No issues. Even fresh update produces the same result very slow.
No device state is changed. If I move or copy these files in Loop, each one by their name, it works fine but when a wild card or pattern is used, it dies.
I took your exact script, replaced the string “SSD_D2” by the name of my mechanical HD.
The list of fileNames was :
Sub A_Data 001 copie 2.jpg
Sub A_Data 001 copie.jpg
Sub A_Data 001.jpg
Sub M2 A_Data Table 7 copie 2.jpg
Sub M2 A_Data Table 7 copie.jpg
Sub M2 A_Data Table 7.jpg
Sub 5 Q_Data 36 copie 2.jpg
Sub 5 Q_Data 36 copie 3.jpg
Sub 5 Q_Data 36 copie 4.jpg
Sub 5 Q_Data 36 copie 5.jpg
Sub 5 Q_Data 36 copie.jpg
Sub 5 Q_Data 36.jpg
Sub Q_Data 63 copie 2.jpg
Sub Q_Data 63 copie.jpg
Sub Q_Data 63.jpg
Sub P4 Q_Data 02 copie 2.jpg
Sub P4 Q_Data 02 copie 3.jpg
Sub P4 Q_Data 02 copie 4.jpg
Sub P4 Q_Data 02 copie 5.jpg
Sub P4 Q_Data 02 copie.jpg
Sub P4 Q_Data 02.jpg
As I wrote, the timer reported : “That took 0,769198060036 seconds.”
I will write a modified version using ASObjC but it would use a loop, not a whose clause.
How are you using your machine ?
Some users let their mac on 24 hours a day, 7 days a week without switching it off from time to time.
Mine is switched off every evening and switched on every morning.
May it make the difference ?
You may look at Activity Manager to see if there is an extraneous process able to fool the machine but I don’t see why it would strike only upon whose clause.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 29 juin 2020 19:25:36
i shut down the mac once every 5-8 hours but the total daily up-time is approx. 10-14 hours.
Activity is normal, idle above 70% nothing unusual as per my knowledge.
Backup using freefilesync works very fast. No change before and after update, copy/move with finder window is as usual.
Can we use shell script ‘mv’ with pattern? I am unable to make syntax for mv command with pattern i.e something like this:
do shell script ("mv -f " & “" & Pattern_A & ".jpg” & space & F_Source & space & F_Answer)
Here is an ASObjC script which moved the described set in 0.009299039841 second
-- Yvan KOENIG (VALLAURIS, France) lundi 29 juin 2020 23:51:12
----------------------------------------------------------------
use AppleScript version "2.5"
use framework "Foundation"
use scripting additions
----------------------------------------------------------------
property |⌘| : a reference to current application
my germaine()
on germaine()
-- Define several datas used by the script
set volName to "SSD_D2" # Edit to fit your needs
set hfsRoot to volName & ":Exam Data:"
set F_Answer to hfsRoot & "Answer:"
set F_Question to hfsRoot & "Question:"
set F_Source to hfsRoot & "Source Data:"
set keyA to "A_Data"
set keyQ to "Q_Data"
set startDate to current application's NSDate's |date|()
set fileManager to a reference to |⌘|'s NSFileManager's defaultManager()
-- Define the URL objects pointing to the three used folders
set URL_Answer to |⌘|'s NSURL's fileURLWithPath:(POSIX path of F_Answer)
set URL_Question to |⌘|'s NSURL's fileURLWithPath:(POSIX path of F_Question)
set URL_Source to |⌘|'s NSURL's fileURLWithPath:(POSIX path of F_Source)
-- Define the options used to rule the enumeration process
set skipsPackageDescendants to |⌘|'s NSDirectoryEnumerationSkipsPackageDescendants as integer --> 2
set skipsHiddenFiles to |⌘|'s NSDirectoryEnumerationSkipsHiddenFiles as integer --> 4
-- Here we warn the tool that we don't want to list available hidden files
-- and that we don't want to scan the content of possible packages available in the source folder
set theOptions to skipsPackageDescendants + skipsHiddenFiles
-- Grab the list of URLs available in the source folder
set theURLs to (fileManager's enumeratorAtURL:URL_Source includingPropertiesForKeys:{} options:theOptions errorHandler:(missing value))'s allObjects()
if (count theURLs) = 0 then error "Le dossier “" & hfsPath & "” est vide."
-- Filter to keep only jpeg files whose name contain "A_Data" or "Q_Data".
-- This way, deciding what to do with each file would be an easy task.
set theFormat to "((self.pathExtension =[c] 'jpg') OR (self.pathExtension =[c] 'jpeg')) AND ((self.lastPathComponent CONTAINS[c] '" & keyA & "') OR (self.lastPathComponent CONTAINS[c] '" & keyQ & "'))" -- Format enhanced
set thePredicate to |⌘|'s NSPredicate's predicateWithFormat:theFormat
set theURLs to (theURLs's filteredArrayUsingPredicate:thePredicate)
if (count theURLs) = 0 then error "Le dossier “" & hfsPath & "” ne contient pas de fichier “jpg” or “jpeg”."
-- loop among the jpeg URLs
repeat with aURL in theURLs -- theURLs is an array
-- grab the name of an URL
set itsName to aURL's lastPathComponent() as string
-- According to the name, define the destination URL
if itsName contains keyA then
set destURL to (URL_Answer's URLByAppendingPathComponent:itsName)
else
set destURL to (URL_Question's URLByAppendingPathComponent:itsName)
end if
-- Move the file into the wanted location
set {theResult, theError} to (fileManager's moveItemAtURL:aURL toURL:destURL |error|:(reference))
end repeat
set timeDiff to startDate's timeIntervalSinceNow()
display dialog "That took " & (-timeDiff as real) & " seconds." --> "That took 0.009299039841 seconds."
end germaine
#=====
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 29 juin 2020 21:13:58
It’s a lightning fast solution. Thank you for your solution. It will be a bit tricky for me to learn this but I will try my best. Thank you so much once again!
In message #6, I added several comments which may help you to understand what is done.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 30 juin 2020 12:15:40