How change an NTFS Volume UUID - macos

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

Related

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 to save your desktop elements (icons, files,folder ) always on the same place with applescript

With the script we are going to create another script where will be store position of all the elements of the desktop, the created script will be compile and usable to put back in place all the elements previously protected.
/adesktopsave/deskico.txt it is the temporary file which will be of use to the compilation.
/adesktopsave/savedicoposition.scpt It is the script of saving that is compiled to be used with applescrit
All the names used here exist that just for the example. These names have no particular property.
It is just necessary to plan to create a folder before using this script. Here it is:
/adesktopsave
Something else, end of line (\n) after " try
"
also " end try
"
and & "}
")
Are very important to respect so that the text is usable.
tell application "Finder" to set theList to {name, desktop position} of items of desktop
try
do shell script "rm -f /adesktopsave/deskico.txt"
do shell script "echo tell application " & quoted form of (quote & "Finder" & quote) & return & " >>/adesktopsave/deskico.txt"
end try
set n to (count (first item of theList))
repeat with i from 1 to n
set inp to do shell script "echo " & quoted form of (item i of first item of theList)
set xy to (item i of second item of theList)
set AppleScript's text item delimiters to ","
set xyz to do shell script "echo " & xy
set wxyz to ("{" & xyz & "}
")
set ligne to "try
" & "set desktop position of item " & quoted form of (quote & inp & quote) & " of desktop to " & quoted form of (wxyz) & "end try
"
set ligne to do shell script "echo " & ligne & " >>/adesktopsave/deskico.txt"
end repeat
do shell script "echo " & "end tell" & return & " >>/adesktopsave/deskico.txt"
display dialog "Do you want to save your icons in their current location?" buttons {"Cancel", "Save"} default button 2 with title "Save the positions of icons"
if (button returned of result) is "Cancel" then
set n to do shell script "echo " & n
else
do shell script "osacompile -o " & "/adesktopsave/savedicoposition.scpt" & " /adesktopsave/deskico.txt"
end if
return n
We can lighten the script to its simplest expression. At the risk of having errors can be.
set ligne to ""
do shell script "mkdir -p /adesktopsave"
tell application "Finder" to set {names, positions} to {name, desktop position} of items of the desktop
set ligne to "tell application \"Finder\"
"
set n to (count names)
set AppleScript's text item delimiters to ","
repeat with i from 1 to n
set ligne to ligne & ("try
" & "set desktop position of item " & (quote & item i of names & quote) & " to {" & item i of positions & "}
end try
")
end repeat
set ligne to ligne & ("end tell" & return)
display dialog "Do you want to save your icons in their current location?" buttons {"Cancel", "Save"} default button 2 with title "Save the positions of icons"
if (button returned of result) is "Cancel" then
set n to do shell script "echo " & n
else
do shell script "osacompile -o " & "/adesktopsave/savedicoposition.scpt -e " & quoted form of ligne
end if
set AppleScript's text item delimiters to ""
tell application "Finder" to open POSIX file "/adesktopsave/savedicoposition.scpt"
return n

Detect battery percentage with applescript

How would I detect what my computer's battery percentage is at and set it to a variable using applescript? All answers to similar questions say to install additional software, but I would like to do this with purely applescript. Is this possible? I've also tried searching through the applescript library with no success.
on run
set theBattString to (do shell script "pmset -g batt")
-- the above will return something like...
-- Now drawing from 'Battery Power' -InternalBattery-0 82%; discharging; 4:06 remaining
end run
Now you can parse theBattString to get the information you'd like from it.
Another option...
on run
do shell script "ioreg -l | grep -i capacity | tr '\\n' ' | ' | awk '{printf(\"%.2f%%\\n\", $10/$5 * 100)}'"
-- will output...
-- 79.63%
end run
The applescript unsigned variable can be used like a signed FileMaker variable... the ** can be removed I tried it Bold it
set batteryPercent to do shell script "pmset -g batt "
tell application "FileMaker Pro.app"
tell table "Power Test Results"
tell record 1
set cell "Test percentage via AppleScript Global" to batteryPercent
end tell
end tell
end tell
Thank ThrowBackDewd for his answer.
I made something a bit strange but it works for me.
Here is the AppleScript
[EDIT]
Here a more efficient code thanks to user #user3439894.
set batteryPercent to word 6 of paragraph 2 of (do shell script "pmset -g batt")
if batteryPercent < 40 then
beep
repeat 3 times
say "Attention " & batteryPercent & "%" & " before shut down."
display notification "Attention " & batteryPercent & "%" & " of charge before shut down." sound name "Glass"
end repeat
end if
idle application
on idle
set batteryPercent to word 6 of paragraph 2 of (do shell script "pmset -g batt")
if batteryPercent < 40 then
repeat 3 times
beep
say "Attention " & batteryPercent & "%" & " of charge before shut down."
display notification "Attention " & batteryPercent & "%" & " of charge before shut down." sound name "Glass"
end repeat
end if
return 60
end idle
[First post]
set theBattString to (do shell script "pmset -g batt")
-- the above will return something like...
-- Now drawing from 'Battery Power' -InternalBattery-0 82%; discharging; 4:06 remaining
set batteryLevel to splitText(theBattString, space)
--set totalItembatLvl to length of batteryLevel
set remainingTime to item 9 of batteryLevel
if remainingTime < "2:40" then
display alert "low battery " & remainingTime & " before shut down."
--batteryLevel & " " & remainingTime
end if
on splitText(theText, theDelimiter)
set AppleScript's text item delimiters to theDelimiter
set theTextItems to every text item of theText
set AppleScript's text item delimiters to ""
return theTextItems
end splitText
on getPositionOfItemInList(theItem, theList)
repeat with a from 1 to count of theList
if item a of theList is theItem then return a
end repeat
return 0
end getPositionOfItemInList
You can add it in an idle statement and check every minute for your battery level.
Any suggestions or corrections will be appreciated.
Regards.

OSX 10.6.8 Xcode 4.2 Change Created and Modified Dates

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

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