Skip to content

Instantly share code, notes, and snippets.

@macsimom
macsimom / active_directory_plug-in_helper.sh
Created March 11, 2025 22:09
An attempt at a bandaid for AD bound Macs that lose their bind due to corrupted credentials
#!/bin/bash
# version 1.4 - Simon Andersen
# set -x
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
DSCONFIGADOUTPUT="$(dsconfigad -show -xml)"
COMPUTERACCOUNT="$(/usr/libexec/PlistBuddy -c "Print ':General Info:Computer Account'" /dev/stdin <<<"$DSCONFIGADOUTPUT")"
if [[ -z "$COMPUTERACCOUNT" ]]; then
echo "Fatal error - No computer account name found"
@macsimom
macsimom / PrinterChooser.applescript.js
Created October 11, 2024 08:02
AppleScript written in JavaScript to get printers from Active Directory and present them in a GUI based list in order to add via the lpadmin command
#!/usr/bin/osascript -l JavaScript
// version 1.1 - 2024 - Simon Andersen
let APP = Application.currentApplication()
APP.includeStandardAdditions = true
function readDefaults(plistfile,propertyKey) {
let theresult = undefined;
try {
theresult = APP.doShellScript("defaults read '"+plistfile+"' '"+propertyKey+"'");
#!/bin/bash
#
# MIT License
#
# Copyright (c) 2024 Simon Andersen
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
@macsimom
macsimom / demobilize_user.py
Created May 31, 2022 21:40
Demobilize a mobile user on macOS
#!/usr/local/munki/munki-python
#
# MIT License
#
# Copyright (c) 2022 Simon Andersen
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// MIT License
//
// Copyright (c) 2022 Simon Andersen
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
@macsimom
macsimom / main.m
Last active January 20, 2022 03:00
openwithrosetta - a tool to check the box "Open with Rosetta" on Apple Silicon Big Sur Macs
//
// main.m
// openwithrosetta
//
// Created by Simon Andersen on 13/09/2021.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@macsimom
macsimom / promote_personal_recovery_key_to_admin_user.sh
Last active July 8, 2021 23:06
Given a valid personal recovery key and an existing user this script elevates the PRK to an actual user and destroys and re-creates the given user with a default password and secure token.
#!/bin/bash
#
# Call this script with the arguments [personal recovery key] [the name of a user to "reset"]
# i.e. "promote_personal_recovery_key_to_admin_user.sh 6323-AHJD-1231-4234-GHJ1-FH23 user1"
# a new user called "another" user is generated. It has the prk with a dash at the end for a password
# a new prk is generated and the user to reset is re-created with the password "password" and a
# newly minted secure token
#set -x
@macsimom
macsimom / EnableARD.sh
Created March 23, 2021 16:40
A short script to enable Apple Remote Desktop (aka. Remote Management) for a given user.
#!/bin/zsh
function ENABLEARD(){
dscl . -create "/Users/${1}" dsAttrTypeNative:naprivs -1073741569
touch "/Library/Application Support/Apple/Remote Desktop/RemoteManagement.launchd"
if ! launchctl list|grep -q com.apple.screensharing ; then
launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plist
fi
echo "Enabled Apple Remote Desktop Management for ${1}"
}
@macsimom
macsimom / build_a_booter_for_fusion.sh
Last active November 18, 2020 12:57
A quick script to convert a macOS recovery partition to a bootable iso intended for VMware Fusion
#!/bin/bash
# Download the script from https://gist.github.com/macsimom/982d507ff94767428e4832ef0fdbdf0c
# Open Terminal
# diskutil list
# Find the device identifer of the recovery partition, eg. "disk1s3"
# call the script with the device indentifier
# bash build_a_booter_for_fusion.sh disk1s3
# An iso file is built at /Users/Shared
#
#!/usr/bin/python
# Version 0.1
# This was (re)written quick and dirty. And by dirty I mean embarrasing.
import subprocess
import tempfile
import os
import re
dfsroot="//example.com/dfs"
dfsrootserveraddress='dfs01.example.com'