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

87 Posts

Post

Replies

Boosts

Views

Activity

False "xcodebuild archive" fail on bamboo/ Monterey/ m1 chip/ Xcode 13.2.1
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!
3
0
3.6k
May ’22
Applying OpenGL Shader to Screen or Window
Hi! I'm looking to create a system utility to apply an openGL shader (or Metal?) to the window that the user is focused on (or the screen), ideally with a keyboard shortcut. From what I can tell, applying OpenGL shaders or pixel level modifications to the whole screens at a time is possible (e.g. BlackLight by Michel Fortin). Any pointers to this kind of thing would be great. Combining Automator workflows with some system-level code seems like it would do the trick but I'm not sure where to start. Update: It looks like CGColorSpace might be helpful for applying color transforms to windows. Perhaps there's a way to make a swift app similar to Rectangle that could modify these CoreGraphics elements instead of the coordinates / transform ones? Thanks for the help, Jack
0
0
2.4k
Apr ’22
write LDAP configuration using OpenDirectory framework in swift
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)
2
0
2.4k
Mar ’22
macOS - shells scripts manually runs but not when automated
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?
1
0
1.1k
Jan ’22
Send message based on mute/unmute change?
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!
3
0
1.5k
Jan ’22
Change the title of the prompt for asking administrative privileges
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
2
0
2k
Dec ’21
False "xcodebuild archive" fail on bamboo/ Monterey/ m1 chip/ Xcode 13.2.1
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!
Replies
3
Boosts
0
Views
3.6k
Activity
May ’22
Applying OpenGL Shader to Screen or Window
Hi! I'm looking to create a system utility to apply an openGL shader (or Metal?) to the window that the user is focused on (or the screen), ideally with a keyboard shortcut. From what I can tell, applying OpenGL shaders or pixel level modifications to the whole screens at a time is possible (e.g. BlackLight by Michel Fortin). Any pointers to this kind of thing would be great. Combining Automator workflows with some system-level code seems like it would do the trick but I'm not sure where to start. Update: It looks like CGColorSpace might be helpful for applying color transforms to windows. Perhaps there's a way to make a swift app similar to Rectangle that could modify these CoreGraphics elements instead of the coordinates / transform ones? Thanks for the help, Jack
Replies
0
Boosts
0
Views
2.4k
Activity
Apr ’22
write LDAP configuration using OpenDirectory framework in swift
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)
Replies
2
Boosts
0
Views
2.4k
Activity
Mar ’22
macOS - shells scripts manually runs but not when automated
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?
Replies
1
Boosts
0
Views
1.1k
Activity
Jan ’22
Send message based on mute/unmute change?
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!
Replies
3
Boosts
0
Views
1.5k
Activity
Jan ’22
Change the title of the prompt for asking administrative privileges
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
Replies
2
Boosts
0
Views
2k
Activity
Dec ’21