• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Have I posted this??
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Have I posted this??


  • Subject: Have I posted this??
  • From: Brian Christmas <email@hidden>
  • Date: Tue, 26 Jun 2018 19:17:41 +1000

G’day folks

I’ve just got out of a months stay in Hospital, starting on 29th May, and
simply can’t remember if I posted this, and asked for comments/suggestions.

I think it’s pretty self explanatory, just look at the word ‘fusion’. While I
don’t remember much of the prior several weeks, I think on re-reading this
code, it might be useful, but am open to/appreciative of, tweaking suggestions.

Apologies if this code started off from someone else’s postings.

Regards

Santa

--
--      Created by: Brian Christmas
--      Created on: 26/5/18
--

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

repeat
        set tempList to (do shell script ("diskutil apfs list")) as text
        try
                set tempFound to word -2 of (paragraph 3 of tempList as text)
as number
                set tempFound to "It appears there is an error, with un-fused .
"
        on error errmsg
                set tempFound to 0
        end try
        set tempReference to ""
        set SearchText1 to "+-- Container disk"
        set SearchText2 to "APFS Container Reference:"
        set nameList to {}
        set foundFlag to 0
        set errorName to 0
        if tempFound = 0 then
                say "I cannot find any un fused logical volumes." without
waiting until completion
                tell application "System Events" to display dialog "I cannot
find any un-fused logical volumes." buttons {"Cancel", "OK"} default button
"Cancel" giving up after 60
                exit repeat
        else
                try
                        set tempReference to words 5 through -1 of (paragraph 3
of tempList as text)
                on error errmsg
                        set tempReference to "error"
                end try
                set tempListTest to tempList as text
                set foundFlag to 0
                repeat with XXX from 1 to count of paragraphs of tempListTest
                        set testParagraph to (paragraph XXX of tempListTest) as
text
                        if foundFlag = 0 then
                                if (words 1 through 2 of testParagraph as text)
contains "APFSContainer" then
                                        set foundFlag to (word 3 of
testParagraph) as number
                                        say (foundFlag as text) & " un fused
logical volumes found." without waiting until completion
                                        exit repeat
                                end if
                        end if
                end repeat
        end if
        set foundlist to {}
        set foundArray to {}
        if foundFlag > 0 then
                set CycleFlag to 0
                repeat with XXX from 1 to count of paragraphs of tempListTest
                        set testParagraph to (paragraph XXX of tempListTest) as
text
                        if testParagraph contains "< Physical Store" then
                                set end of foundlist to word 5 of testParagraph
as text
                                set temp to ""
                                repeat with x from 6 to (count of words of
testParagraph) of testParagraph
                                        set temp to temp & word x of
testParagraph
                                        if x < (count of words of
testParagraph) then set temp to temp & "-" as text
                                end repeat
                                set end of foundlist to temp
                                set CycleFlag to CycleFlag + 1
                        end if
                        if CycleFlag = 2 then
                                if testParagraph contains "Name:" then
                                        set temp to ""
                                        try
                                                set oldDelims to AppleScript's
text item delimiters -- save their current state
                                                set AppleScript's text item
delimiters to {":", "("} -- declare new delimiters
                                                set tempName to text item 2 of
testParagraph
                                                set AppleScript's text item
delimiters to oldDelims -- restore them
                                        on error
                                                set errorName to errorName + 1
                                                set tempName to "Error " &
errorName as text
                                                set AppleScript's text item
delimiters to oldDelims -- restore them in case something went wrong
                                        end try
                                        try
                                                repeat while character 1 of
tempName = " "
                                                        set tempName to
characters 2 through -1 of tempName as text
                                                end repeat
                                        end try
                                        try
                                                repeat while character -1 of
tempName = " "
                                                        set tempName to
characters 1 through -2 of tempName as text
                                                end repeat
                                        end try
                                        set end of foundlist to tempName
                                        set end of nameList to tempName
                                        set CycleFlag to 0
                                        set end of foundArray to foundlist
                                        set foundlist to {}
                                end if
                        end if
                end repeat
        else
                tell application "System Events" to display dialog "I cannot
find any un-fused logical volumes." buttons {"Cancel", "OK"} default button
"Cancel" giving up after 60

                exit repeat
        end if
        repeat
                set mychoice to (choose from list {nameList} with prompt
"Copyright OzSanta." & return & return & "Please indicate which drives you want
to fuse as Fusion Drives..." & return & return & "You will be offered a choice
to rename your selection." & return default items "None" OK button name
{"Fuse"} cancel button name {"Cancel"})
                if mychoice is false then error number -128 -- user
canceledtempList & return & foundlist & return & item 1 of foundArray & return
                set theResponse to display dialog "Do you want to change the
Title that this Fusion will be named?" default answer mychoice with icon note
buttons {"Cancel", "Continue"} default button "Continue" giving up after 120
                tell application "System Events" to display dialog "Just making
ABSOLUTELY sure?, " & return & return & (text returned of theResponse) buttons
{"This is Correct!", "Wrong, Re-enter"} default button "This is Correct!"
giving up after 120
                if button returned of the result is "This is Correct!" then
exit repeat
        end repeat
        repeat with yy from 1 to count of items of nameList
                if item yy of nameList as text = mychoice as text then
                        try
                                do shell script ("diskutil apfs unlockVolume
/dev/" & item yy of nameList)
                        on error errmsg
                        end try
                        try
                                do shell script ("diskutil apfs unMount /dev/"
& item yy of nameList)
                        on error errmsg
                        end try
                        exit repeat
                end if
        end repeat
        try
                do shell script ("diskutil cs create " & mychoice & " " & (item
1 of item yy of foundArray) & " " & (item 3 of item yy of foundArray))
                set tempListTestTwo to do shell script ("diskutil cs list")
                set testTrue to false
                repeat with YYY from 1 to count of paragraphs in tempListTestTwo
                        set testParagraph to (paragraph YYY of tempListTestTwo)
as text
                        if testParagraph contains "Logical Volume Group" then
                                set foundMatchingDisk to word 5 of
testParagraph as text
                                set tempLogicGroup to ""
                                repeat with x from 6 to (count of words of
testParagraph) of testParagraph
                                        set tempLogicGroup to tempLogicGroup &
word x of testParagraph
                                        if x < (count of words of
testParagraph) then set tempLogicGroup to tempLogicGroup & "-" as text
                                end repeat
                        end if
                        if testParagraph contains "Volume Name:" and
testParagraph contains mychoice then
                                set testTrue to true
                                exit repeat
                        end if
                end repeat
                if testTrue then
                        do shell script ("diskutil cs createVolume " &
tempLogicGroup & " jhfs+ " & mychoice & " 100%")
                end if
        on error errmsg number errnum
                tell application "System Events" to display dialog "There may
have been an error!" & return & return & "Please note the Error is.... " &
return & "    '" & errmsg & "'." giving up after 120
                exit repeat
        end try
end repeat

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: AppleScript with FileMaker
  • Next by Date: Re: Have I posted this??
  • Previous by thread: Re: AppleScript script unable to respond to a script statement correctly
  • Next by thread: Re: Have I posted this??
  • Index(es):
    • Date
    • Thread