Applescript Shell Script Progress

I am creating applescript that creates a backup image of the / Users folder on Mac Os X. I would like to do one of two things:

  • Or the barber’s progress bar will be displayed when the shell script is running with the ability to exit.
  • Display a dialog box when a script is run with the option to exit.

I tried to make a shell script with / dev / null, but ignored all the output. I would like to save the output and display it in a dialog box for the user.

Here is my code:

set computername to (do shell script "networksetup -getcomputername")
set fin to ""
set theIcon to note
tell application "Finder"
    try
        set folderalias to "/Users"
        set foldersize to physical size of folder (alias ":Users") --(info for folderalias) 
        set foldersize to (round ((foldersize / 1.0E+9) * 100)) / 100
    on error
        tell application "System Events"
            set foldersize to (round (((get physical size of folder ":Users" as text) / 1.0E+9) * 100)) / 100
        end tell
    end try
end tell

display dialog "User profile backup utility" & return & return & ¬
    "The computer name is: " & computername & return & return & ¬
    "The '/Users/' directory size is: " & "~" & foldersize & " GB" & return & return & ¬
    "Would you like to backup the '/User' directory now?" & return ¬
    buttons {"Cancel", "Backup Now"} default button "Backup Now"
set comd to "hdiutil create ~/Desktop/" & computername & ".dmg -srcfolder /test/"
set fin to do shell script (comd) with administrator privileges
display dialog fin
+3
source share
2 answers

AppleScript (, ), Shane Stanleys ASObjC Runner, , , . ,

tell application "ASObjC Runner"
    reset progress
    set properties of progress window to {button title:"Abort Backup", button visible:true, message:"Backing up the '" & (POSIX path of folderalias) & "' directory.", detail:"There are " & foldersize & " GB of data to backup – this might take some time.", indeterminate:true}
    activate
    show progress
end tell
try -- to make sure we destroy the dialog even if the script error out
    <your backup operation here>
end try   
tell application "ASObjC Runner" to hide progress

( " " ) - , ( AS). , do shell script - , fin [ ASObjC Runner.

ASObjC Runner AppleScript ( script AppleScript), Resources ( Finder, Show Package Contents ) path to resource , using terms from block - , , , , , : tell POSIX- (tell application (POSIX path of (path to resource "ASObjC Runner.app"))).

:

  • /Users:

    path to users folder
    

    - Finder. POSIX path of , , quoted form of POSIX path of.

  • Id , physical size - Finder, . tell application "Finder" try … catch ( , , ), error -10004, round tell).
  • fin - do shell script.
  • do shell script, , computerName .
  • theIcon .
  • , display alert display dialog , .
  • - AppleScript , , ...

, :

set computerName to do shell script "networksetup -getcomputername"
set folderAlias to path to users folder
tell application "System Events" to set folderSize to physical size of folderAlias
set folderSize to round(folderSize / 1.0E+9 * 100) / 100

display alert "User profile backup utility" message ¬
  "The computer name is: " & computerName & return & return & ¬
  "The '" & (POSIX path of folderAlias) & "' directory size is: " & "~" & folderSize & " GB" & return & return & ¬
  "Would you like to backup the '" & (POSIX path of folderAlias) & "' directory now?" & return ¬
  buttons {"Cancel", "Backup Now"} default button "Backup Now"
set shellCmd to "hdiutil create ~/Desktop/'" & computerName & "'.dmg -srcfolder /test/"
-- progress bar dialog display initialization goes here
try
    set shellOutput to do shell script shellCmd with administrator privileges
end try
-- progress bar dialog hiding goes here
display dialog shellOutput
+5

, , - .

set comd to "hdiutil create -puppetstrings '~/Desktop/" & computername & ".dmg' -srcfolder '/test/'"
tell application "Terminal" to do script comd
0

All Articles