OSX 10.6.8 Xcode 4.2 Change Created and Modified Dates - xcode

I've been working on an Applescript to change the creation and modification dates of a particular file via (do shell script). The first script with a manually input date works fine, but the second script which uses the (current date command) with an appended time, throws an error code, even though the output from both scripts appears to be the same. Any help would be most appreciated.
Script #1
resetFile()
on resetFile()
do shell script "SetFile -d '02/18/2016 00:01:00' ~/Desktop/Test.txt"
do shell script "SetFile -m '02/18/2016 00:01:00' ~/Desktop/Test.txt"
end resetFile
Script #2
resetFile()
on resetFile()
set {year:y, month:m, day:d} to (current date)
set {year:y, month:m, day:d} to result
if (d * 1) < 10 then
if (m * 1) < 10 then
set dateTime to quoted form of ("0" & m * 1 & "/" & "0" & d * 1 & "/" & y * 1 & " " & "00:01:00") as string
else
set dateTime to quoted form of (m * 1 & "/" & "0" & d * 1 & "/" & y * 1 & " " & "00:01:00") as string
end if
else
if (m * 1) < 10 then
set dateTime to quoted form of ("0" & m * 1 & "/" & d * 1 & "/" & y * 1 & " " & "00:01:00") as string
else
set dateTime to quoted form of (m * 1 & "/" & d * 1 & "/" & y * 1 & " " & "00:01:00") as string
end if
end if
display dialog dateTime
do shell script "SetFile -d dateTime ~/Desktop/Test.txt"
do shell script "SetFile -m dateTime ~/Desktop/Test.txt"
end resetFile

This is a simpler version to create the date string. It uses a handler to add leading zeros if needed:
resetFile()
on resetFile()
set {year:y, month:m, day:d} to (current date)
set dateTime to quoted form of (pad(m as integer) & "/" & pad(d) & "/" & y & space & "00:01:00")
display dialog dateTime
do shell script "SetFile -d " & dateTime & " ~/Desktop/Test.txt"
do shell script "SetFile -m " & dateTime & " ~/Desktop/Test.txt"
end resetFile
on pad(v)
return text -2 thru -1 of ((v + 100) as text)
end pad

Related

AppleScript that scrapes a website for data with curl function not working after some time making it

The code below used to work at scraping the trading value of a cryptocurrency website. Now it prints the name of the crypto and the time it was read but no value. Is it because the curl function isn't working anymore? Any help is appreciated.
The code uses a curl function to call the value of the crypto every 5 seconds. I got the code from a helpful stack overflow user and it worked well when I implemented it but it doesn't return the monetary value anymore. It creates a log file to the desktop and writes in the background as an application.
property eGrepBitcoinPrice : "priceValue\">\\$\\d{2},\\d{3}.\\d{2}"
property eGrepLitecoinPrice : "priceValue\">\\$\\d{2}.\\d{2}"
property eGrepDogecoinPrice : "priceValue\">\\$\\d{1}.\\d{5}"
property currentBitcoinPrice : missing value
property currentLitecoinPrice : missing value
property currentDogecoinPrice : missing value
property logToTextFile : missing value
on run -- Executed Only Once.. When This Script Applet Is Launched
activate
set logToTextFile to (display dialog ¬
"Enable Quick Log Mode?" buttons {"No", "Yes"} ¬
default button 2 with title "Log Mode")
if button returned of logToTextFile = "Yes" then
my logCommands's beginLog()
getPrices()
else
getPrices()
return {currentBitcoinPrice, currentDogecoinPrice, currentLitecoinPrice}
end if
end run
on idle
getPrices()
try
if button returned of logToTextFile = "Yes" then my logCommands's writeToLog()
on error errMsg number errNum
my logCommands's writeToLog()
end try
(* within this idle handler is where you will place
The bulk of your additional code. All of your Excel
Code Goes Here*)
return 5 -- In Seconds, How Often To Run Code In This Idle Handler
end idle
---------- PLACE ALL ADDITIONAL HANDLERS BENEATH THIS LINE ----------
on getPrices()
set currentBitcoinPrice to do shell script ¬
"curl --no-keepalive 'https://coinmarketcap.com/currencies/bitcoin/markets/' " & ¬
"| grep -Eo " & quoted form of eGrepBitcoinPrice & " | cut -c 14-"
set currentLitecoinPrice to do shell script ¬
"curl --no-keepalive 'https://coinmarketcap.com/currencies/litecoin/' " & ¬
"| grep -Eo " & quoted form of eGrepLitecoinPrice & " | cut -c 14-"
set currentDogecoinPrice to do shell script ¬
"curl --no-keepalive 'https://coinmarketcap.com/currencies/dogecoin/' " & ¬
"| grep -Eo " & quoted form of eGrepDogecoinPrice & " | cut -c 14-"
end getPrices
on quit -- Executed Only When The Script Quits
if button returned of logToTextFile = "Yes" then my logCommands's endLog()
continue quit -- Allows The Script To Quit
end quit
script logCommands
property pathToPriceLog : POSIX path of (path to desktop as text) & "Price Log.txt"
on beginLog()
set startTime to ("Start Time... " & (current date) as text) & ¬
" Price Scanning At 5 Minute Intervals"
do shell script "echo " & startTime & " >> " & ¬
quoted form of pathToPriceLog
end beginLog
on writeToLog()
do shell script "echo " & "Bitcoin:" & quoted form of currentBitcoinPrice & ¬
" Dogecoin:" & quoted form of currentDogecoinPrice & ¬
" Litecoin:" & quoted form of currentLitecoinPrice & ¬
" " & quoted form of (time string of (current date)) & ¬
" >> " & quoted form of pathToPriceLog
end writeToLog
on endLog()
set endTime to quoted form of "End Time... " & (current date) as text
do shell script "echo " & endTime & " >> " & ¬
quoted form of pathToPriceLog
do shell script "echo " & " " & " >> " & ¬
quoted form of pathToPriceLog
end endLog
end script

Applescript Error: "Can’t make Can’t make some object into type some object."

I just updated to Catalina and one of my applescripts no longer works. Wondering if anyone has any ideas as to why? All of the folders selected (single or batch) are on a work server.
The result I get from the Script Editor after selecting a folder is:
-- 'ascr''err '{ '----':'utxt'("Can’t make Can’t make some object
into type some object."), 'errn':-1700,
'erob':'alis'("file:///System/Volumes/Data/data/ARLSCAN2/DIGI/ORIG/FRETSCHEL/Auto/DONE/F2509")
}
--Script Name:
set ScriptName to "jhoveValidation"
--Define user name
set userName to do shell script "whoami"
--Initalize ErrorCount
set errorCount to 0
--Initalize stampCount
set stampCount to 0
-- BEGIN SCRIPT!
--Option to change location mode
set locationModeChoice to display dialog "Would you like to check a single box folder or batch check a directory of box folders?" buttons ["Exit", "Single", "Batch"] default button 3 with title ScriptName with icon caution
set locationModeChoice to button returned of locationModeChoice
if locationModeChoice = "Exit" then
return
end if
if locationModeChoice = "Single" then
set imageDirectory to choose folder with prompt "Select Single Box Folder"
else if locationModeChoice = "Batch" then
set customFolder to choose folder with prompt "Please select a folder of box folders with standard ICT hierarchy:"
set masterFolder to customFolder
end if
-- BEGIN PREFLIGHT
--Populates list of files in finder
set progress description to "jhoveValidation"
set progress additional description to "Loading box and file information..."
set progress total steps to -1
delay 1
if locationModeChoice = "Batch" then
tell application "Finder"
set masterList to folders in masterFolder
if (count of items in masterList) is 0 then
display dialog "ERROR: No files were detected" buttons ["Quit"]
return
end if
end tell
else if locationModeChoice = "Single" then
set masterList to {}
set masterList to masterList & imageDirectory
end if
-- BEGIN IMAGE PROCESSING
set folderCount to count masterList
set folderCounter to 1
repeat with aFolder in masterList
set currentWorkingBox to getLastPathItem(aFolder)
tell application "Finder"
try
set inputFolder to (every folder in aFolder whose name begins with "TIFF") as alias
on error
display dialog "There was an error finding your TIFF folder for box:
" & currentWorkingBox & "
Please place the images you want to inspect in a completed box folder with a TIFF folder inside." buttons ["Quit"]
return
end try
end tell
set progress description to (currentWorkingBox as text) & ": jhoveValidation - Box " & folderCounter & " of " & folderCount
set progress additional description to "Loading TIFF files..."
set progress total steps to -1
tell application "Finder"
try
set filesList to files in inputFolder
set filesCount to count filesList
on error
display dialog "There was an error finding your TIFF folder for box:
" & currentWorkingBox & "
Please place the images you want to inspect in a completed box folder with a TIFF folder inside." buttons ["Quit"]
return
end try
end tell
--***BEGIN LOOP***
--Individual file processing begins here
set loggingCounter to 0
set totalSteps to count filesList
set progress total steps to totalSteps
repeat with aFile in filesList
set loggingCounter to loggingCounter + 1
log loggingCounter
set progress additional description to "Processing file " & loggingCounter & " of " & totalSteps
set progress completed steps to loggingCounter
set AppleScript's text item delimiters to "."
if (the last text item of (aFile as text) is "tif") then
tell application "Finder"
set theFile to aFile as alias
set theFilePath to POSIX path of theFile
log theFilePath
end tell
do shell script "cd ~/Desktop/jhove; ./jhove -c conf/jhove.conf -l SEVERE -o " & (theFilePath as text) & ".txt -m TIFF-hul " & theFilePath
else
end if
end repeat
set progress additional description to "Processing Results & Generating Reports..."
set progress total steps to -1
set currentWorkingFolderPath to POSIX path of (aFolder as alias)
try
do shell script "mkdir " & currentWorkingFolderPath & "VALIDATION"
end try
do shell script "mv " & currentWorkingFolderPath & "TIFF/*.txt " & currentWorkingFolderPath & "VALIDATION"
do shell script "grep -H 'Status' " & currentWorkingFolderPath & "VALIDATION/*.txt | sed 's/:/,/' > " & currentWorkingFolderPath & "VALIDATION/results.csv"
set theResults to {}
set theResults to theResults & paragraphs of (do shell script "cat " & currentWorkingFolderPath & "VALIDATION/results.csv")
set resultsCount to count theResults
set rejectList to {}
set reportStatus to "PASS"
set passCounter to 0
set failCounter to 0
repeat with aResult in theResults
set AppleScript's text item delimiters to ","
log text item 2 of aResult
set thisVar to text item 2 of aResult
if (text item 2 of aResult as text) = " Status: Well-Formed and valid" then
set passCounter to passCounter + 1
log "PASS"
else
set failCounter to failCounter + 1
set rejectList to rejectList & aResult
set reportStatus to "FAIL"
log "FAIL"
end if
end repeat
set totalCount to passCounter + failCounter
if reportStatus = "PASS" then
do shell script "echo \"All files have passed JHOVE Validation.\" > " & currentWorkingFolderPath & "jhoveReport.txt"
do shell script "echo \" \" >> " & currentWorkingFolderPath & "jhoveReport.txt"
do shell script "echo \"" & passCounter & " files were validated.\" >> " & currentWorkingFolderPath & "jhoveReport.txt"
do shell script "echo \" \" >> " & currentWorkingFolderPath & "jhoveReport.txt"
do shell script "date >> " & currentWorkingFolderPath & "jhoveReport.txt"
else
do shell script "echo \"!!! ATTENTION - some files have failed JHOVE Validation!!! \" > " & currentWorkingFolderPath & "jhoveReport.txt"
do shell script "echo \"" & passCounter & " files passed.\" >> " & currentWorkingFolderPath & "jhoveReport.txt"
do shell script "echo \"" & failCounter & " files failed.\" >> " & currentWorkingFolderPath & "jhoveReport.txt"
do shell script "echo \" \" >> " & currentWorkingFolderPath & "jhoveReport.txt"
do shell script "echo \"----- \" >> " & currentWorkingFolderPath & "jhoveReport.txt"
do shell script "echo \"The following have reported failed JHOVE Validation: \" >> " & currentWorkingFolderPath & "jhoveReport.txt"
repeat with aReject in rejectList
do shell script "echo \"" & aReject & "\" >> " & currentWorkingFolderPath & "jhoveReport.txt"
end repeat
do shell script "echo \" \" >> " & currentWorkingFolderPath & "jhoveReport.txt"
do shell script "echo \"----- \" >> " & currentWorkingFolderPath & "jhoveReport.txt"
do shell script "date >> " & currentWorkingFolderPath & "jhoveReport.txt"
end if
set folderCounter to folderCounter + 1
end repeat
--***END LOOP***
-- END SCRIPT
-- Function: Returns the document name without extension (if present)
on getBaseName(fName)
set baseName to fName
repeat with idx from 1 to (length of fName)
if (item idx of fName = ".") then
set baseName to (items 1 thru (idx - 1) of fName) as string
end if
end repeat
return baseName
end getBaseName
on getLastPathItem(thePathToParse)
set thePathToParse to (thePathToParse as text)
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set lastPathLength to the number of text items in thePathToParse
set lastPathTarget to lastPathLength - 1
set the lastPathItemItem to text item lastPathTarget of thePathToParse
set AppleScript's text item delimiters to oldDelims
return lastPathItemItem
end getLastPathItem
on getLastPathItemFile(thePathToParse)
set thePathToParse to (thePathToParse as text)
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set the lastPathItemItem to the last text item of thePathToParse
set AppleScript's text item delimiters to oldDelims
return lastPathItemItem
end getLastPathItemFile

How change an NTFS Volume UUID

Does anybody have a solution to change the "Volume UUID" on Mac ?
I have this when using diskutil info from mac os x
Below is the applescript script to read UUID from an NTFS partition. All sudo are to be completed for your name and password, otherwise try removing the sudo. I do not advise you to modify the UUID, there is no information on their use. I left the inversion of the bytes in a very rudimentary way.
set hdd to {}
set dmg to do shell script "sudo ls /dev/disk**s** " & " | sed -e 's#[[:space:]]*$##;s#\\/dev\\/##;/^$/d'" user name "Your_Name" password "Your_Password" with administrator privileges
set doun to ""
set dor to ""
set uuidd to ""
set uuidd to {}
set hfsountfs to ""
set theVol1 to ""
set theVol to ""
set vhd to ""
set leplus to 0
set levhd to ""
set hd to {}
set _Result to the paragraphs of dmg
set n to 0
set n to count _Result
set j to 1
do shell script "echo " & n
repeat with i from 1 to n
set end of hdd to item i of _Result
end repeat
set theVolumeTemp to (choose from list hdd with prompt "Choisissez le Volume (partition) NTFS :" with empty selection allowed)
if theVolumeTemp is not false then
set theVolumeTemp to do shell script "echo " & theVolumeTemp
set theVol to "/dev/" & theVolumeTemp
set theVol1 to theVol
set theVol to do shell script "echo " & theVol & " | xxd -p | sed 's#0a##' | xxd -r -p "
try
set vhd to do shell script "diskutil info " & theVol & " | grep 'Disk Image' "
end try
try
set uuidd to do shell script "diskutil unmount " & theVol
end try
set uuidd to do shell script "sudo dd if=" & theVol & " iseek=48 bs=1 count=8 | xxd -p " user name "Your_Name" password "Your_Password" with administrator privileges
set theVol to do shell script "echo " & uuidd
set n to 0
set n to count uuidd
do shell script "echo " & n
repeat with i from 1 to 8
set les2 to (item (n - 1) of uuidd & item n of uuidd)
set end of hd to les2
set n to n - 2
end repeat
set hd to do shell script "echo " & hd
set nDec to (do shell script "perl -e 'printf(hex(\"" & hd & "\"))'") as integer
if vhd is not "" then
set leplus to 3320
set levhd to "c'est un Vhd ntfs"
else
set leplus to 3352
end if
set nDec to do shell script " echo $((" & nDec & " * 4096 + " & leplus & "))" as string
set uuidd to do shell script "sudo dd if=" & theVol1 & " iseek=" & nDec & " bs=1 count=16 | xxd -p " user name "Your_Name" password "Your_Password" with administrator privileges
set hd to {}
set n to 8
repeat with i from 1 to 4
set les2 to (item (n - 1) of uuidd & item n of uuidd)
set end of hd to les2
set n to n - 2
end repeat
set end of hd to "-"
set n to 12
repeat with i from 1 to 2
set les2 to (item (n - 1) of uuidd & item n of uuidd)
set end of hd to les2
set n to n - 2
end repeat
set end of hd to "-"
set n to 16
repeat with i from 1 to 2
set les2 to (item (n - 1) of uuidd & item n of uuidd)
set end of hd to les2
set n to n - 2
end repeat
set end of hd to "-"
repeat with i from 17 to 20
set end of hd to item (i) of uuidd
end repeat
set end of hd to "-"
repeat with i from 21 to 32
set end of hd to item (i) of uuidd
end repeat
set hd to do shell script "echo " & hd
set lamft to do shell script " echo $((" & nDec & " - " & leplus & "))" as string
set doun to " Identifiant Universel Unique ou UUID du " & theVolumeTemp & " est :
" & hd
set doun to doun & "
La MFT du " & theVolumeTemp & " est à : " & lamft & " Octets du départ de la partition " & "
l'UUID se trouve plus loin de " & leplus & " Octets " & "
" & levhd
set uuiddd to do shell script "sudo dd if=" & theVol1 & " iseek=72 bs=1 count=8 | xxd -p " user name "Your_Name" password "Your_Password" with administrator privileges
set n to 0
set n to count uuiddd
do shell script "echo " & n
set uuiddd to do shell script "echo " & uuiddd & " | tr [:lower:] [:upper:] "
set hdd to {}
set les2 to (item 15 of uuiddd & item 16 of uuiddd & item 13 of uuiddd & item 14 of uuiddd)
set end of hdd to les2
set end of hdd to "-"
set les2 to (item 11 of uuiddd & item 12 of uuiddd & item 9 of uuiddd & item 10 of uuiddd)
set end of hdd to les2
set end of hdd to "-"
set les2 to (item 7 of uuiddd & item 8 of uuiddd & item 5 of uuiddd & item 6 of uuiddd)
set end of hdd to les2
set end of hdd to "-"
set les2 to (item 3 of uuiddd & item 4 of uuiddd & item 1 of uuiddd & item 2 of uuiddd)
set end of hdd to les2
set doun to doun & " Le numero de série des 8 Octets de l'offset 72 partition NTFS du " & theVolumeTemp & " est :
" & uuiddd & "
Toujours présenté sous cette forme : " & hdd
display alert (doun as string)
try
do shell script "diskutil mount " & theVol1
end try
end if
I am not sure about Mac but why would you use NTFS there.
But for Windows you could try the Set-Disk powershell command with the -Guid parameter.
Cheers,
Gabriel

Auto Import Script not Working

I'm an absolute beginner with VB hence I might ask some silly questions.
I have a VB script getting triggered via a Batch file which results in data being imported for last day.
Below is the code for VB and Batch file.
Please let me know if you see any error in the code.
VB Script
rem
rem XLink_Import.vbs
rem
Set oShell = WScript.CreateObject("WScript.Shell")
' filename = oShell.ExpandEnvironmentStrings("today_xlink.bat")
' Set objFileSystem = CreateObject("Scripting.fileSystemObject")
' Set oFile = objFileSystem.CreateTextFile(filename, TRUE)
Dim i
Dim ImportStartOffset, ImportedNumberOfDays
If WScript.Arguments.length > 0 Then
For i=0 to WScript.Arguments.length-1
Arg = WScript.Arguments(i)
If Left(Arg,1) = "-" Then
If ( Arg = "-o" ) Then
ImportStartOffset = WScript.Arguments(i+1)
End if
If ( Arg = "-n" or Arg = "-l" ) Then
ImportedNumberOfDays = WScript.Arguments(i+1)
End if
End if
Next
End If
rem Prepare the import start date
Dim Dy, Mth
Dim ImportDate
ImportDate = Now + ImportStartOffset
Dy = Day(ImportDate)
Mth = Month(ImportDate)
If Len(Dy) = 1 Then Dy = "0" & Dy
If Len(Mth) = 1 Then Mth = "0" & Mth
ImportStartDate = Dy & "/" & Mth & "/" & Year(ImportDate)
rem Prepare import script to run (not useed yet)
rem oFile.WriteLine("isps_ul.exe -t -d " & todaydate & " -L 1")
rem oFile.Close
rem Run XLink import
wscript.echo "isps_ul.exe -t -d " & ImportStartDate & " -L " & ImportedNumberOfDays
oShell.Run "isps_ul.exe -t -d " & ImportStartDate & " -L " & ImportedNumberOfDays, 1, true
Batch File
#echo off
rem
rem XLink_Import.bat
rem
rem Manually starts an Xlink import starting today + a StartOffset of some days.
rem Imported number of days can also be set.
rem
set ImportStartOffset=0
set ImportedNumberOfDays=1
cscript XLink_Import.vbs -o %ImportStartOffset% -n %ImportedNumberOfDays%
pause
You don't need both a batch and a script, one of either would be enough, doing the whole thing in batch would require with some suggling with special parameters and I'm not into that so I'll adapt your script a bit like below.
Since you keep your 2 confiuration variables in the windows environment you can read them from vbscript as well, other option would be to read from a configuration file, from the command line like you did or keep the in the script itself.
Your middle part, makig sure the date is speleld correct could be omitted if you set those dates correctly in the configuration (environmentvariables).
If your import is going to work you should check before by running what is displayed as command, so eg "eisps_ul.exe -t -d28/11/2016 -L" should run, otherwise search on that problem first.
What I meant in my comment about being DRY means you should not repeat things, in case of your command you can store the concatenated command in a variable and use that for viewing and running.
Dim ImportStartOffset, ImportedNumberOfDays, oShell, command, Dy, Mth, ImportDate, ImportStartDate
Constant WaitOnReturn = true, WindowStyle = 1 '1 = Activate and display
'read configuration environment variables
Set oShell = CreateObject( "WScript.Shell" )
ImportStartOffset = wshShell.ExpandEnvironmentStrings( "%ImportStartOffset%" )
ImportedNumberOfDays = wshShell.ExpandEnvironmentStrings( "%ImportedNumberOfDays%" )
'Prepare the import start date (not necessary if environmentvariables would be configured well)
ImportDate = Now + ImportStartOffset
Dy = Day(ImportDate)
Mth = Month(ImportDate)
If Len(Dy) = 1 Then Dy = "0" & Dy
If Len(Mth) = 1 Then Mth = "0" & Mth
ImportStartDate = Dy & "/" & Mth & "/" & Year(ImportDate)
'Run XLink import
command = "isps_ul.exe -t -d " & ImportStartDate & " -L " & ImportedNumberOfDays
wscript.echo command
oShell.Run command, WindowStyle, WaitOnReturn
Set oShell = Nothing

Move Files X Per Folder

I've put a script together that moves a predefined number of files into folders that are created sequentially.
It seems somewhat sluggish and being new to this I'm wondering if there's a more elegant do shell script command to aid in this.
set filesPerFolder to 100
set zeroPad to 3
tell application "Finder" to set chosenFolder to (target of Finder window 1) as text
set thisDir to POSIX path of chosenFolder
set folderCount to 1
repeat
set folderCount to zero_pad(folderCount, zeroPad)
set filesToMove to (do shell script "ls -1 " & thisDir & " | wc -l") as integer
if filesToMove is 0 then
return
end if
set theNewFolder to thisDir & folderCount
set asDir to POSIX file theNewFolder
tell application "Finder"
if exists asDir then
-- do nothing
else
do shell script "mkdir -p " & theNewFolder
end if
end tell
tell application "Finder" to set firstFile to first file of folder chosenFolder as alias
set fileToMove to POSIX path of firstFile
set theMove to quoted form of fileToMove & " '" & theNewFolder & "/'"
do shell script "mv -f " & theMove
set filesInFolder to (do shell script "ls -1 " & theNewFolder & " | wc -l") as integer
if filesInFolder ≥ 10 then
set folderCount to folderCount + 1
end if
end repeat
on zero_pad(value, string_length)
set string_zeroes to ""
set digits_to_pad to string_length - (length of (value as string))
if digits_to_pad > 0 then
repeat digits_to_pad times
set string_zeroes to string_zeroes & "0" as string
end repeat
end if
set padded_value to string_zeroes & value as string
return padded_value
end zero_pad
Thanks to Lri's shell command the script is leaner and efficient.
tell application "Finder" to set thisDir to (target of Finder window 1) as string
set rootDirectory to quoted form of POSIX path of thisDir
set counTed to (do shell script "ls -1 " & rootDirectory & " | wc -l") as integer
set filesToMove to (do shell script "ls -2 " & rootDirectory & " | wc -l") as integer
if filesToMove is 0 then
display alert "There are no files in the root of this directory to move."
return
end if
set filesPerFolder to text returned of (display dialog "There are " & counTed & " files in this folder.
How many files would you like to move per folder: " default answer "100")
set fileCount to (do shell script "cd " & rootDirectory & " && i=0;for f in *;do d=$(printf %03d $((i/" & filesPerFolder & "+1)));let i++;mkdir -p $d;mv \"$f\" $d;done")
set filesLeft to (do shell script "ls -2 " & rootDirectory & " | wc -l") as integer
if filesLeft is 0 then
display alert "Completed."
return
end if
i=0;for f in *;do d=$(printf %03d $((i/100+1)));let i++;mkdir -p $d;mv "$f" $d;done
Or using GNU parallel:
ls|parallel -k -N100 x=\$\(printf %03d {#}\)\;mkdir -p \$x\;mv {} \$x
-k keeps the order of the lines and {#} is the sequence number.

Resources