Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<plugin name="AutoPkg Recipe" id="com.scriptingsosx.autopkg-recipe-definition" version="1.0" xmlns:plisteditpro="http://www.fatcatsoftware.com/plisteditpro">
<extension point="com.apple.xcode.plist.structure-definition" name="AutoPkg Recipe" id="com.scriptingosx.autopkg-recipe-definition">
<definition name="_root_" localizedString="AutoPkg Recipe" class="Dictionary" identifyingKey="Identifier">
<dictionaryKeys>
<key name="Comment" localizedString="Comment" class="String" use="optional"></key>
<key name="Description" localizedString="Description" class="String" use="default"></key>
<key name="Identifier" localizedString="Identifier" class="String" use="required"></key>
<key name="Input" localizedString="Input" class="Input" use="required"></key>
<key name="MinimumVersion" localizedString="MinimumVersion" class="String" use="default"></key>
@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 / 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 / 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 / os_version.sh
Last active April 15, 2023 10:04
Sample bash script to show how to parse the macOS version
#!/bin/bash
# use argument 1 as the version or get it from sw_vers
os_ver=${1-:$(sw_vers -productVersion)}
# string comparison
if [[ "$os_ver" == 10.13.* ]]; then
echo "macOS High Sierra"
elif [[ "$os_ver" == 10.12.* ]]; then
echo "macOS Sierra"
@scriptingosx
scriptingosx / allusers.sh
Created November 19, 2018 08:41
This script will try to determine a list of members of the given group and list all members (macOS)
#!/bin/bash
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
# allusers.sh
#
# 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
@scriptingosx
scriptingosx / create_netloc.py
Last active March 5, 2023 03:09
Create OS X inetloc files
#!/usr/bin/python
import sys
import argparse
import urlparse
import urllib
import plistlib
import os.path
import subprocess