Skip to content

Instantly share code, notes, and snippets.

@scriptingosx
scriptingosx / getDefaultAppForURL.sh
Created August 18, 2023 12:36
two scripts to set and read default app for url schemes (http, mailto, ssh, etc.) for use with Jamf Pro
#!/bin/bash
# this script will return the current default application for a url scheme
# for use as a Jamf Extension attribute
# by Armin Briegel - Scripting OS X
# Permission is granted to use this code in any way you want.
# Credit would be nice, but not obligatory.
# Provided "as is", without warranty of any kind, express or implied.
@scriptingosx
scriptingosx / 1-Voices.swift
Last active August 14, 2023 07:41
Process Sample Code
import Foundation
let process = Process()
process.launchPath = "/usr/bin/say"
process.arguments = ["-v", "?"]
let outPipe = Pipe()
process.standardOutput = outPipe
process.terminationHandler = { process in
let outData = outPipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: outData, encoding: .utf8) ?? ""
@scriptingosx
scriptingosx / ConfigureXcode.sh
Created July 27, 2023 11:11
Configure Xcode post installation script with SDK download for Xcode 14 and 15
#!/bin/sh
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
xcodePath="/Applications/Xcode.app"
if [ ! -e "$xcodePath" ]; then
echo "no app at $xcodePath, exiting..."
exit 1
fi
@scriptingosx
scriptingosx / ChooserUI.mobileconfig
Last active May 19, 2023 13:29
The files you will need to follow along the creation of the "Chooser" example app from my MacSysAdmin Online 2021 presentation.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PayloadContent</key>
<array>
<dict>
<key>PayloadContent</key>
<dict>
<key>com.scriptingosx.ChooserUI</key>
@scriptingosx
scriptingosx / Build Package and Notarize
Last active February 27, 2023 18:09
Use this as a Archive Post-action in Xcode for command line tool projects. More details in this post: https://scriptingosx.com/?p=1588
# Developer ID Installer cert name
sign_cert="Developer ID Installer: Name (ABCD123456)"
# profile name used with `notarytool --store-credentials`
credential_profile="notary-example.com"
# data from build settings
pkg_name="$PRODUCT_NAME"
identifier="$PRODUCT_BUNDLE_IDENTIFIER"
version="$MARKETING_VERSION"
@scriptingosx
scriptingosx / runAsUser.sh
Last active January 31, 2024 15:28
template script for macOS which can run a command as the currently logged in user. https://scriptingosx.com/2020/08/running-a-command-as-another-user/
#!/bin/sh
# template script for running a command as user
# The presumption is that this script will be executed as root from a launch daemon
# or from some management agent. To execute a single command as the current user
# you can use the `runAsUser` function below.
# by Armin Briegel - Scripting OS X
#
@scriptingosx
scriptingosx / pkgAndNotarize.sh
Created September 10, 2019 12:46
Script that builds, packages and notarizes an Xcode command line tool.
#!/bin/zsh
# pkgAndNotarize.sh
# 2019 - Armin Briegel - Scripting OS X
# place a copy of this script in in the project folder
# when run it will build for installation,
# create a pkg from the product,
# upload the pkg for notarization and monitor the notarization status
@scriptingosx
scriptingosx / bash_prompt.sh
Last active June 23, 2022 19:13
Sample code for dynamic bash prompt that shows exit codes.
# PROMPT
# default macOS prompt is: \h:\W \u\$
# assemble the prompt string PS1
# inspired from: https://stackoverflow.com/a/16715681
function __build_prompt {
local EXIT="$?" # store current exit code
# define some colors
@scriptingosx
scriptingosx / InstallerBuilds.sh
Created March 28, 2019 14:19
This script will print the build numbers of the macOS version from all installer apps
#!/bin/bash
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
installerBuildVersion() { # $1 path to the installer app
installerApp=${1:?"no path for installer"}
# echo "inspecting: $installerApp"
if [[ -d "$installerApp" ]]; then
identifier=$(/usr/libexec/PlistBuddy -c "print CFBundleIdentifier" "$installerApp/Contents/Info.plist")
@scriptingosx
scriptingosx / checkmembers.sh
Created November 19, 2018 08:42
This script will loop through all users and use dseditgroup to check if they are a member of a given group (macOS)
#!/bin/bash
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
# checkusers
#
# written by Armin Briegel, Scripting OS X, 2018
#
# code is provided as is, with no guarantees that it will work etc.
# adapt and use as you will