Skip to content

Instantly share code, notes, and snippets.

@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 / userpictures.sh
Created October 23, 2018 07:24
sample script that loops through all users and sets a different user picture.
#!/bin/bash
# create an array from all images in the User Pictures subfolders
IFS=$'\n' read -rd '' -a pictures <<< "$(find '/Library/User Pictures/Fun' -name *.tif -print )"
# loop through all users
picIndex=0
@scriptingosx
scriptingosx / setdesktop.sh
Last active January 31, 2023 15:02
Sample script to set the desktop with desktoppr
#!/bin/sh
##
## sets the desktop using `desktoppr`
##
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
# set the path to the desktop image file here
picturepath="/Library/Desktop Pictures/BoringBlueDesktop.png"
@scriptingosx
scriptingosx / com.scriptingosx.setdesktop.plist
Created September 14, 2018 12:56
simple LaunchAgent plist which re-sets the desktop at login with desktoppr https://github.com/scriptingosx/desktoppr
<?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>Label</key>
<string>com.scriptingosx.setdesktop</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/desktoppr</string>
<string>/Library/Desktop Pictures/BoringBlueDesktop.png</string>
@scriptingosx
scriptingosx / desktop_picture_boringblue.mobileconfig
Last active November 18, 2020 22:58
sample configuration profile to set the desktop picture.
<?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>PayloadDisplayName</key>
<string>Desktop</string>
<key>PayloadEnabled</key>
@scriptingosx
scriptingosx / EmptyProfile.mobileconfig
Last active August 17, 2018 12:14
Empty Mobile Configuration file suitable as a placeholder for certain operations
<?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>PayloadDescription</key>
<string>Empty Profile that controls nothing</string>
<key>PayloadDisplayName</key>
@scriptingosx
scriptingosx / bashdisplay.sh
Last active December 10, 2022 15:51
bash functions using osascript to use some user interaction on macOS
#!/bin/bash
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
consoleUser() {
echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }'
}
displaydialog() { # $1: message
message=${1:-"Message"}
@scriptingosx
scriptingosx / techs.sh
Last active October 15, 2019 13:49
Sample script to modify authorization db on macOS
#!/bin/bash
# modify the system.preferences right
/usr/bin/security authorizationdb write system.preferences <<EndOfPlist
<?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>allow-root</key>
<true/>
@scriptingosx
scriptingosx / computerimage.py
Created January 9, 2018 14:37
Cocoa Python code to generate an image file for the current Mac model
#!/usr/bin/python
from Cocoa import NSImage, NSImageNameComputer, NSSize, NSMakeSize, NSMakeRect, NSBitmapImageRep, NSPNGFileType, NSData
from CoreGraphics import CGImage
from objc import NULL
size = NSMakeSize(512, 512)
image = NSImage.imageNamed_(NSImageNameComputer)
image.setSize_(size)
@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"