![]() ![]() I’ve used similar methods for many tasks over the years, although I usually use the Satimage.osax AppleScript Extension and regular expressions to parse tables. This kind of table-based system is much easier to work with and maintain than a bunch of If-statements or AppleScript records. I’ve left the mount line commented, so you’ll need to uncomment it when you’re ready to try it out. If ddButton = "Copy" then set the clipboard to e Repeat with i in paragraphs of networkDisks Set AppleScript's text item delimiters to "/" Tell application "Finder" to set diskNameList to name of disks I don’t have a network here to test with, so you’ll have to be the guinea pig. So let’s change things around and make it easy to maintain. There’s nothing wrong with that methodology, except that it becomes more and more difficult to maintain as the list gets longer. Mount volume “afp://192.168.2.101/Multimedia” as user name “admin” with password "mypassword"ĭisplay notification "Multimedia Mounted" Mount volume “afp://192.168.2.101/USBDisk2” as user name “admin” with password "mypassword" ![]() Mount volume “afp://192.168.2.101/USBDisk1” as user name “admin” with password "mypassword" Mount volume “afp://192.168.2.101/Rachel Files” as user name “admin” with password "mypassword"ĭisplay notification "Rachel Files Mounted" Mount volume “afp://192.168.2.101/Stuff” as user name “admin” with password "mypassword" Mount volume “afp://192.168.2.101/Qsync” as user name “admin” with password "mypassword" Mount volume “afp://192.168.2.101/Movies” as user name “admin” with password "mypassword" Mount volume “afp://192.168.2.101/Mac Documents” as user name “admin” with password "mypassword"ĭisplay notification "Mac Documents Mounted" If not (disk “Mac Documents” exists) then Mount volume “afp://192.168.2.101/Download” as user name “admin” with password "mypassword" Mount volume “afp://192.168.2.101/Art work Files” as user name “admin” with password "mypassword"ĭisplay notification "Art work Files Mounted" If not (disk “Art work Files” exists) then ![]() Mount volume “afp://192.168.2.101/FaceBook Pictures” as user name “admin” with password "mypassword"ĭisplay notification "FaceBook Pictures Mounted" If not (disk “FaceBook Pictures” exists) then I had a problem with the last one it would try to mount volumes over and over, this way it checks first but I think it’s fat… I think this could be smaller… What do you think ccstone? Persistent variables will often bite the hand that feeds them, unless they are given the proper care. You can of course set the value of the variable from within the script rather than as a result of the script.īTW: I prefer to use camel-case or underscores in variable names to make them more readable: You’ll see that the script above will return a value of “Success” if it successfully finishes mounting the drives, and it will return “Failed” if the it errors-out.īut the initial condition of the “Mounteddrives” variable should be something else. Mount volume volume volume volume "Success"Īt the beginning of your macro use a Set Variable to Text Action to set “Mounteddrives” to NULL or FALSE or something else relevant. tell app "Finder" to open location Mount volumes Display Dialog needs a context when run from Keyboard Maestro. If you’re running from the Finder then it’s desirable to wrap the on-error display dialog call in such a block, because Keyboard Maestro will eat it otherwise. The commands used are from the Standard Additions.osax. Your AppleScript does not require a Finder-Tell-Block. ![]() You need to initialize the variable at the beginning of your script (or macro) OR reset the state when the macro exits. If you have a test that uses the variable it won’t necessarily be reliable because of the saved-state. If you assign “Success” to that variable it will keep it forever. One thing you have to look out for is variable state. You were already saving to Mounteddrives from within the script, so as far as I can see there was no reason to output the result to the variable. Set value of variable "Mounteddrives" to "Success" Tell application "Keyboard Maestro Engine" Mount volume volume volume volume Error handlerĭisplay dialog errs & " " & errn with icon 2ĭisplay notification "SERVER not responding to ping." tell app "Finder" to open location Mount volumes If k > max_retry then error "Server is not responding for predefined period." number 8000 Repeat while (do shell script "ping -c 1 ") contains "100% packet loss" BUT when I run script through KM variable "Mounteddrives" is true then sets to not true? empty? tell application "Finder" When I run this script through Script editor variable "Mounteddrives" is true in KM. ![]()
0 Comments
Leave a Reply. |