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 marked as Apple Recommended
1.4k Views
Has anyone been able to find any documentation on XCUITest? I haven't had much success with it. I've watched the video a few times and it doesn't work as easily as is shown. I can't find any other sources of documentation other than reading the few comments in a couple of header files. I'm so frustrated...
Posted
by
jos
Post marked as Apple Recommended
1.1k Views
I have started to experiment with Xcode UI testing and with in my first few tests, I am observing that the app state is being retained between tests.How I kill the app completely?http://masilotti.com/xctest-documentation/Classes/XCUIApplication.html#//api/name/terminatecommand only seems to put the app in background/suspend it
Posted
by
Post marked as Apple Recommended
1.2k Views
Hello,I have unique requirement where i want to use automation frameworks such as XCUITest etc. to be able to automate 3rd party apps. I know that the XCode 8 now has native support however so far from what i can tell it only works if you have access to source code?In my case the app is available as a binary and there is no source code access available/possible? In this case any recommendations how Ui based autoamtion can be built and used?Previoulsy i was able to use UiAutomation framework but that has been depcreated in latest XCode. In the new XCUITest framework I havent been able to sort out how to target a 3rd party app installed on the iPhone and automate that.Any help would be appreciated.Thanks
Posted
by
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
Post marked as solved
10 Replies
6.5k Views
Hi guys,someone else has encountered this error with XCode 10 and Mojave? A simple fragment of code, that works fine on applescript, fail during the compilation on XCode with the error "Not authorized to send Apple Events to System Events. (error -1743).on applicationWillFinishLaunching_(aNotification) tell application "System Events" -- any fragment of code that comes to mind tell appearance preferences set dark mode to not dark mode end tell end tell end applicationWillFinishLaunching_ I have searched in google but I have not found anything,thanks for help
Posted
by
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
Post not yet marked as solved
2 Replies
750 Views
i'm tying to create a custom LDAP configuration in a swift script, something similar to this without using python: https://github.com/Yohan460/Programmatic-OD-Python-Binding my script fails at the custom call - not sure if the issue is my data types or that the functions used in the python example don't exactly translate. any help is appreciated, thanks in advance! p.s - i'm a total swift n00b #!/usr/bin/swift import Foundation import OpenDirectory let fileName = "ldap.plist" let configData = try String(contentsOfFile: fileName) let config = Data(configData.utf8) let odSesh = ODSession.default() let configNode = try! ODNode(session: odSesh,type: ODNodeType(kODNodeTypeConfigure)) let outNode = try! configNode.customCall(99991, send: config)
Posted
by
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
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
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
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
Post not yet marked as solved
2 Replies
1.1k Views
I have simple script to turn down the brightness of my MacBook Pro via an AppleScript. This worked fine in BigSur, but has stopped working after I upgraded to Monterey 12.0.1. The script is as follows: tell application "System Preferences" reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays" end tell tell application "System Events" to tell process "System Preferences" to tell window "Built-in Retina Display" set value of value indicator 1 of slider 1 of tab group 1 to 0.0 end tell ..error is as follows in script editor: error "System Events got an error: Can’t set window \"Built-in Retina Display\" of process \"System Preferences\" to 0.0." number -10006 from window "Built-in Retina Display" of process "System Preferences" Any suggestions on what to modify to get it working again?
Posted
by
Post not yet marked as solved
2 Replies
558 Views
I have a Java program that I run in Eclipse which executes AppleScript for certain tasks. It works fine in Mojave, but in Big Sur, the AppleScripts fail with the error "AppleScript Not authorized to send Apple events to [app] (-1743)" In Mojave, the user is prompted (one time on the first run) with "'Eclipse.app' wants access to control '[app being controlled by Applescript]'" Once this prompt is approved, then Eclipse is added in the System Preferences under Security & Privacy -> Privacy -> Automation and a checkbox is included and activate for each of the applications that the AppleScript manipulates (Finder and iTunes or Music app depending on OS version), and thereafter,  my Java program can run its AppleScripts. In Big Sur, the prompts never appear and the AppleScript immediately errors out. Furthermore, I see no way to manually add approvals under System Preferences -> Security & Privacy -> Privacy -> Automation and there is no way I can find for how I can approve this automation on my own Mac. How do I invoke AppleScript on Big Sur from other languages such as Java? Please note that the Java program constructs AppleScript content at run time dependent on data, so the scripts are not fixed.  The Java code to run a script goes like this....   String script = <Some expression to form the content of the script depending on data>; String[] myargs = { "osascript", "-e", script}; try {     Process process = runtime.exec(myargs);     process.waitFor(); // Wait for the script to complete.     if (process.exitValue() == 0) { // Success       //On Mojave, execution takes this path and //Applescript works, after the one time user //approval.         System.out.println("success");     } else { // Fail         //On Big Sur, executions takes this path and //outputs         //35:57: execution error: Not authorized to send //Apple events to Finder. (-1743)         InputStream is = process.getErrorStream();       final BufferedReader reader = new BufferedReader(new InputStreamReader(is));         String line = null;         while ((line = reader.readLine()) != null) {             System.out.println(line);         }         reader.close();     } } catch (Exception exc) {     System.out.println(exc.getMessage());    } Thanks in advance for any help!
Posted
by
Post not yet marked as solved
2 Replies
537 Views
Until Big Sur I was asking the administrative privileges using the command /usr/bin/osascript -e 'do shell script "ls" with prompt "Installer is trying to setup" with administrator privileges' which gives me this dialog box Now the same command in mac os monetery is giving me the prompt with the title as "osascript". How can I replace the osascript title with my app name. Thanks in advance
Posted
by
Post not yet marked as solved
3 Replies
320 Views
Trying to figure out if this is even possible- here's what I'd love to be able to do: Start script Send message "X" via TCP/UDP OR HTTP OR OSC if system audio input is muted, send message "Y" if unmuted. Continue to watch and send a new message when the mic is muted or unmuted until the script stopped. Not sure if this is even possible- any suggestions on proper nomenclature to start my research would be most appreciated!
Posted
by
Post not yet marked as solved
1 Replies
273 Views
Trying to automated running this shell script and getting the results. So I have a shell script: backup.sh -- finds latest backup time machine backup date, creates a file on the desktop called bkDate.txt then added the date into the file. #!/bin/sh enabled=`/usr/bin/defaults read /Library/Preferences/com.apple.TimeMachine AutoBackup` if [ "$enabled" == "1" ];then lastBackupTimestamp=`date -j -f "%a %b %d %T %Z %Y" "$(/usr/libexec/PlistBuddy -c "Print Destinations:0:SnapshotDates" /Library/Preferences/com.apple.TimeMachine.plist | tail -n 2 | head -n 1 | awk '{$1=$1};1')" "+%Y-%m-%d %H:%M:%S"` echo "$lastBackupTimestamp" else echo "<result>Disabled</result>" fi echo "$lastBackupTimestamp" > ~/Desktop/bkDate.txt If I run it manually through sh ~/Desktop/backup.sh it works if I use automator (shell or AppleScript) or crontab. It produces the file but the contents is empty. Trying to figure out why it's not letting me automate it and how would can I automate the file and output?
Posted
by
Post not yet marked as solved
0 Replies
368 Views
Does anyone know how to automate the install of Xcode Command Line Tools? Bonus points for doing it in a supportable Apple method, and if possible, leveraging the macOS version of Bash I've tried this method: (sorry, this forum won't allow the link) xcode-select --install sleep 1 osascript &lt;&lt;EOD tell application "System Events" tell process "Install Command Line Developer Tools" keystroke return click button "Agree" of window "License Agreement" end tell end tell EOD This automation fails because on first-run, the Security &amp; Privacy wants (user) approval for: Accessibility &gt; sshd-keygen-wrapper: annoying (bottom) This approval must be provided before the install but there is no way to manually approve before the install, nor automate the approval during the install At least not as far as far as I can see. Any help is appreciated. TIA
Posted
by
Post not yet marked as solved
1 Replies
610 Views
In the past I used this script as groundwork for a little helper which swaps the Modifier Keys (CMD, OPT, CTRL) for me, when a specific application getting focused and unfocused. With MacOS 12.3 Apple finally removed Python2 Not a big deal, if you reinstall it via Homebrew and update all your Python scripts. But what is about Apple related modules like NSWorkspace from AppKit? Code: try: from AppKit import NSWorkspace except ImportError: print "Can't import AppKit -- maybe you're running python from brew?" print "Try running with Apple's /usr/bin/python instead." exit(1) This code returns reasonably the print-message. Question Is this not available anymore? Because the homebrew version can't find this and Python3 seems also not to know it. Is NSWorkspace for Python now deprecated?
Posted
by
Post marked as solved
3 Replies
1.1k Views
This is so strange I'm at a loss. Background: I am a DevOps engineer validating that our iOS build scripts can run via Bamboo on new Mac mini M1 machines. Out of the box, these machines are running Monterey, while our in-use machines are all still on Big Sur. Tldr; After modifying security permissions for our custom CI keychain so it's accessible by Xcode's CLI tools (specifically, the codesign and security utilities) the "xcodebuild archive" command we run fails with NO logged errors, causing bamboo to fail the build. However, the "failed" command produces a VALID xcarchive file. If I force the archive step to exit with a zero status, the subsequent "xcodebuild exportArchive" step successfully generates a valid .ipa that can be submitted to Testflight and run as expected. I've never seen anything like this. Details: Initially, our builds were failing with codesigning errors related to the CLI tools interacting with our custom keychain (we use a custom keychain so Bamboo only has access to the codesigning assets it needs, this is best practice, at least up til now.) We could build on the new Mac mini with Xcode IDE just fine, and we could even build from the commandline on the new Mac mini. However, running the same commands via ssh to the new Mac mini from my local machine produced the same error bamboo was getting. We were getting errors like this: 23-Mar-2022 13:35:58 Warning: unable to build chain to self-signed root for signer "Apple Development: Elizabeth Goldstein (XXXXXXX)" 23-Mar-2022 13:35:58 /Users/bamboo/agent-home/xml-data/build-dir/path/to/Build/Products/QA-iphoneos/Shared.framework: errSecInternalComponent 23-Mar-2022 13:35:58 Command CodeSign failed with a nonzero exit code We were already unlocking the keychain as part of the build script, and the private key was set to "Allow all access" for outside applications (two common issues that might raise this error.) Finally, I rebuilt the system keychain by first deleting then manually re-importing Apple's root signing certificates from terminal like this: sudo security import ./AppleWWDRCA.cer -k /Library/Keychains/System.keychain -T /usr/bin/codesign -T /usr/bin/security -T /usr/bin/productbuild sudo security import ./AppleWWDRCAG3.cer -k /Library/Keychains/System.keychain -T /usr/bin/codesign -T /usr/bin/security -T /usr/bin/productbuild Then I deleted and re-imported my company's signing assets into our custom keychain like this: security import ./appstore-cert.p12 -k /Users/bamboo/Library/Keychains/our-ci.keychain-db -T /usr/bin/codesign -T /usr/bin/security -T /usr/bin/productbuild security import ./dev-cert.p12 -k /Users/bamboo/Library/Keychains/our-ci.keychain-db -T /usr/bin/codesign -T /usr/bin/security -T /usr/bin/productbuild So now, there are zero errors in the log that I can find, but bamboo still fails when we run these commands: /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -workspace OUR-APP.xcworkspace -scheme iPhoneApp-QA clean build -configuration QA -derivedDataPath output -sdk iphoneos OTHER_CFLAGS="-fembed-bitcode" ENABLE_BITCODE=YES BITCODE_GENERATION_MODE=bitcode /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -workspace OUR-APP.xcworkspace -scheme iPhoneApp-QA -sdk iphoneos -configuration QA -derivedDataPath output archive -archivePath build.xcarchive OTHER_CFLAGS="-fembed-bitcode" ENABLE_BITCODE=YES BITCODE_GENERATION_MODE=bitcode If I change it to /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -workspace OUR-APP.xcworkspace -scheme iPhoneApp-QA -sdk iphoneos -configuration QA -derivedDataPath output archive -archivePath build.xcarchive OTHER_CFLAGS="-fembed-bitcode" ENABLE_BITCODE=YES BITCODE_GENERATION_MODE=bitcode || exit 0 The final exportArchive command generates a valid .ipa Any help or ideas would be greatly appreciated, since of course that's not a viable workaround, nor is pinning our OS to Big Sur forever, and we need to scale up our CI system. Thank you for reading this far!
Posted
by