Scripting

RSS for tag

Scripting allows you to automate complex, repetitive, and time-consuming tasks by writing scripts that interact with apps, processes, and the operating system.

Posts under Scripting tag

27 Posts
Sort by:
Post not yet marked as solved
2 Replies
499 Views
Hi! I am new to OSX Shell Script and am trying to work my way into it. I don't get the expected outcome with the following snippet of my script code and I have no idea, why. I read most of the Apple Shell Script Pimer and googled a lot about it, but to no avail. I want to check the current username against some given usernames and set the value of a variable depending on the outcome. I used awk inside the shell script to get this done, but for some reason the for loop inside the awk part seems to change the value of the current username with every loop. This is the code: #!/bin/zsh awk -v u=$USER 'BEGIN {        print "Username outside loop is " u;       count[0] = "Anton";       count[1] = "Bert";       count[2] = "Carl";                                 for ( c_num in count ) {             print "Username inside loop is " u;             print "Compare to "count[c_num];                                                 if (u = count[c_num]) {                   test_var = "X";             } else {                   test_var = "Y";             }             print test_var;       } }' And this is what I get after I run it in terminal: Username outside loop is Zac Username inside loop is Zac Compare to Carl X Username inside loop is Carl Compare to Anton X Username inside loop is Anton Compare to Bert X I don't see why 'u' is changed every loop. I'm thankful for every help / advice! Markus
Posted
by mmhld.
Last updated
.
Post not yet marked as solved
2 Replies
559 Views
Script Example: sudo dscl . -create /Users/ITAdmin sudo dscl . -create /Users/ITAdmin UserShell /bin/bash sudo dscl . -create /Users/ITAdmin RealName ITAdmin sudo dscl . -create /Users/ITAdmin UniqueID 502 sudo dscl . -create /Users/ITAdmin PrimaryGroupID 20 sudo dscl . -create /Users/ITAdmin NFSHomeDirectory /Local/Users/ITAdmin sudo dscl . -create /Users/ITAdmin NFSHomeDirectory /Users/[ITuser] sudo dscl . -passwd /Users/ITAdmin [password] sudo dscl . -append /Groups/admin GroupMembership ITAdmin When using this locally or remotely, it works except the Home folder does not create or show up in the UI. After further testing, it does show up after an initial first time login. With our remote workforce and the secondary reasons for needing this script, we're trying to find a way to mimic a user login to add into our actual other script so that the home folder is created without actual end user interaction (won't be possible.) Or are there any other alternative ways to script a new admin user account? (Or a better place to ask this?) Thanks in advanced!
Posted
by livmanger.
Last updated
.
Post not yet marked as solved
0 Replies
418 Views
For an IT department initiative, we have to remotely remove admin rights from a subset of M1 Macbook Air users. Their computers were set up manually with one original admin user account. After much research and testing, the admin rights removal portion of our scripting is working except for the original admin user account. A few niche online resources indicated this might possibly be due to M1's having a new type of user account called an owner. I also read that any secondary accounts after the initial one should have access to the OIK and OIC so we're confused why admin rights aren't getting removed from that original user when it works on other secondary accounts in multiple ways of testing. Any ideas or context surrounding this elusive new owner type of account, why the working script won't remove admin rights from that account but will for others, or if there's some missing info in order to accomplish this goal? We ideally would like to add an IT managed admin user and remove admin from the original user (current MDM does not support his inherently so we're getting creative.)
Posted
by livmanger.
Last updated
.
Post marked as solved
1 Replies
513 Views
I am attempting to record memory leak information from the terminal in 2 different ways: launch automated test through 'xcodebuild', run xctrace -record, attaching to the PID of the test (I look for it Activity Monitor). Launch my app in the simulator and run xctrace, attaching to the PID of my app. in both cases I get the following failures: [ERROR] Run issues detected (trace is still ready to be viewed): dlopen(/Applications/Xcode.app/Contents/SharedFrameworks/DVTInstrumentsFoundation.framework/Resources/liboainject.dylib, 10): no suitable image found.  Did find: /Applications/Xcode.app/Contents/SharedFrameworks/DVTInstrumentsFoundation.framework/Resources/liboainject.dylib: mach-o, but not built for platform iOS-sim dlopen(/Applications/Xcode.app/Contents/SharedFrameworks/DVTInstrumentsFoundation.framework/Resources/liboainject.dylib, 10): no suitable image found.  Did find: /Applications/Xcode.app/Contents/SharedFrameworks/DVTInstrumentsFoundation.framework/Resources/liboainject.dylib: mach-o, but not built for platform iOS-sim Error retrieving leak information. An error occurred trying to capture Leaks data. Error retrieving leak information. what are these .dylibs? and how do I rebuild them for iOS-sim?
Posted
by zmanx.
Last updated
.
Post not yet marked as solved
0 Replies
1.2k Views
I can't seem to find any more-or-less "official" place to discuss JavaScript for Automation (JXA). I've managed to develop some level of skill at JXA, although I have a long way to go.What I want to know is, is there some place I can go to both contribute my knowledge, and get some answers?Here's one example of a situation where I have no idea where to go to for answers:Let's say I have an object that I want to turn into a plist XML string. I use code like this:function serializeObjectToXmlPlist(obj) { var data = $.NSPropertyListSerialization .dataWithPropertyListFormatOptionsError( $(obj), $.NSPropertyListXMLFormat_v1_0, 0, null); var nsString = $.NSString.alloc .initWithDataEncoding(data, $.NSUTF8StringEncoding); return $(nsString).js; }The problem with this code is that if there are any nodes of type "data" (which contain base64-encoded strings), their content does not get serialized to the XML string.Where do I go to find answers to questions like this?Thanks.
Posted
by dagware.
Last updated
.
Post not yet marked as solved
0 Replies
442 Views
I have been searching the Internet for a solution to automatically update a Google sheet doc with a dynamic CSV file hosted in Google drive. I have come across some paid solutions but nothing that works for the do-it-yourself users. Linking a CVS file to a google sheet doc using the =IMPORTDATA(“”) works but does not update the google sheet when the CVS file changes. I am unsure if hosting the CSV file on Google drive creates issues when synching to a Google docs sheet.  Also, I try the Google script editor but was not able to make the Google sheet update automatically after setting up the update CVS function and trigger. Has anyone found a way to automatically update a Google sheet with a dynamic CVS file? Is this a simple or complicated process?
Posted
by pase.
Last updated
.