Skip to content
/ MacOps Public

MacOps - macOS automate, control apps, system. AppleScript, JavaScript for automation, shell scripts. Script Editor on Mac.

License

Notifications You must be signed in to change notification settings

ego/MacOps

Repository files navigation

MacOps

Backup data from major macOS Applications.

Motivation

Sometimes application state can be broken, so we need a way to restore it, especially when macOS cannot do it (after update).

Run these scripts before close App, reboot, upgrade macOS.

Install

git clone https://github.com/ego/MacOps.git

Usage

Partial backups

cd MacOps/

./Backup.sh

Note: Sublime tabs should be run manually

Sublime-save-tabs.py

Backup location user HOME directory with nested structure by apps

~/Workspaces/Homebrew/$(date '+%Y-%m-%d-%H')
~/Workspaces/iTerm2/Tabs/$(date '+%Y-%m-%d-%H').txt
# and so on ..

Full copy of Applications folders

./Backup-applications.sh

Partial features:

  • Homebrew save Brewfile and brew --list commands

./Homebrew-save-brewfile.sh

  • iTerm2 save open current Tabs

./iTerm2-save-tabs.sh

  • Safari save open current Tabs

./Safari-save-tabs.sh

  • Finder save open current Tabs

./Finder-save-tabs.sh

  • Sublime save files history

./Sublime-save-files-history.sh

  • Sublime save open current Tabs

Open Sublime and go to View/Show Console

and paste content from

Sublime-save-tabs.py

Restore Safari Tabs

See README

Safari Bookmarks and History Analytics

See README

  • Compare Bookmarks.plist with History.db:

add_bookmarks_to_history.py plus Query.sql

  • Save last session plist to csv file

last_session_plist_to_csv

  • Save Safari history to HTML files

TODO: save_history_to_html.py

Debug

AppleScript and JavaScript for Automation (JXA). Python and Bash for scripting.

Use Script Editor on Mac

open osascript/Debug.scpt

Print logs or alert pop-ups:

console.log("") and app.displayDialog("")

var app = Application.currentApplication()
app.includeStandardAdditions = true

var array = ["Sal", "Ben", "David", "Chris"]
var arrayLength = array.length

for (var i = 0; i < arrayLength; i++) {
    var currentArrayItem = array[i]
    // Process the current array item
    app.displayDialog(`${currentArrayItem} is item ${i + 1} in the array.`)
}

Mac Automation Scripting Guide

JXA

Closing lots of Safari tabs with JXA

JavaScript for Automation

Apple JavaScript for Automation

Introduction to AppleScript Language Guide

PyXA appscript py-appscript pyobjc

ls operation not permitted

Profiles - Where Firefox stores your bookmarks, passwords and other user data

Notes.app - how to access history