AnsweredAssumed Answered

Script example for MAC or Windows that makes a directory using Command line or AppleScript

Question asked by MarcMcCall on May 31, 2012
Latest reply on Jun 9, 2015 by FentonJones

Title

Script example for MAC or Windows that makes a directory using Command line or AppleScript

Post

Here is an example of a script that works on MAC or windows, that creates a directory on the desktop and creates a backup of the DB.  The script includes comand line or AppleScript steps to perform this.

Have Fun!!!!!

  • Allow User Abort [ Off ]
  • Set Error Capture [ On ]
  • #--------------------------------------Freezes the window and navigates to the Preferences Screen....
  • Freeze Window
  • #
  • #--------------------------------------Sets the name of the folder to be created on the user's Desktop...
  • Set Variable [ $dirName; Value:"Products_Backups" ]
  • If [ Abs ( Get ( SystemPlatform ) ) - 1 //windows ]
  • #--------------------------------------If the current operating system is a Windows machine...
  • #--------------------------------------A folder will be created using the $dirName variable if the folder is not already created.
  • Set Variable [ $desktopUse; Value:Substitute ( "/" & Get ( DesktopPath ); [ "//" ; "" ]; [ "/" ; "\\" ]) ]
  • Send Event [ open document/application; "cmd.exe /C MKDIR " & Quote ( $desktopUse & $dirName & "\\" ) ]
  • Else
  • #--------------------------------------If the current operating system is not a Windows machine, meaning that if it is a Mac...
  • #--------------------------------------A folder will be created using the $dirName variable if the folder is not already created.
  • Perform AppleScript [ Native AppleScript: set theOutputFolderPath to path to desktop folder set theNewFolderName to "Products_Backups" tell application "Finder" if (exists folder (theOutputFolderPath & theNewFolderName as string)) = false then make new folder at desktop with properties {name:theNewFolderName} end if end tell ]
  • End If
  • #--------------------------------------The file name is set in variables based on the current Date and Time, and a copy of the Databse is saved to the appropriate folder on the user's Desktop.
  • Set Variable [ $filename; Value:GetAsText ("Products" & "_" & GetAsText( Substitute ( Get (CurrentDate) ; "/" ; "_")) & "_" & Substitute ( Substitute ( GetAsText (Get(CurrentTime)) ; ":" ; "" ) ; " " ; "") & ".fp7") ]
  • Set Variable [ $output; Value:"file" & Case ( Abs ( Get ( SystemPlatform ) ) - 1 ; "win:" ; "mac:" ) & Get ( DesktopPath ) & $dirName & "/" & $filename ]
  • Save a Copy as [ “$output” ] [ copy of current file ]
  • Set Variable [ $error; Value:Get ( LastError ) ]
  • #
  • Refresh Window [ Flush cached join results; Flush cached SQL data ]
  • If [ $error ]
  • #--------------------------------------If there was an error in the saving of the backup, an error dialog will display...
  • If [ $error = 3 ]
  • Show Custom Dialog [ Title: "Backup Error:"; Message: "There was an error making the Backup of your Database. You may only make a backup with a local copy of this database."; Buttons: “OK” ]
  • Else
  • Show Custom Dialog [ Title: "Backup Error:"; Message: "There was an error making the Backup of your Database. Database was not backed up. Error: " & $error; Buttons: “OK” ]
  • End If
  • Else
  • #--------------------------------------If the Database saved successfully, a dialog will display alerting the user to the fact...
  • Show Custom Dialog [ Title: "Backup"; Message: "Your Database has been backed up successfully."; Buttons: “OK” ]
  • End If 

Outcomes