Giter Club home page Giter Club logo

macos-script-login-logout's Introduction

macOS (macOSX) Login/Logout Script .

Launchagent script to execute a command or shell script at user login or logout. This works on macOS High Sierra 10.13.6 Last avbl MacOs on my hardware (mid 2010) It will work on the High Sierra and most probably on on some older osx versions. The newer I don't I just can't test it. If someone with MacOs higher then High Sierra 10.13.6 Test this, that would be nice.

Automatic Install and Uninstall with install.sh

If the service was already installed and or loaded , the service will first be unloaded and uninstalled.

If the user answered Yes to the question to uninstall. Else the script will be stopped.

After uninstallation User can answer Yes to reinstall the service or No to just have it removed.

When install,uninstall and or reinstall is done user can choose to keep or remove git repo.

Logging of this script.

After Automatic install the logs will be in the users default log directory which is:

  • $HOME/Library/Logs/login-logout.log
  • $HOME/Library/Logs/login-logout.err

example if You're user alfred it will be /Users/alfred/Library/Logs/login-logout.log From out of finder You find the Library map in you're home map. But finder uses local language if choosen by user. In dutch for example they call the Library map Bibliotheek.

Off course if during install You change the logs location the logs will be somewhere else. There is well a limit You can not set a log path below users home dir. This is the same for the script file login-logout.sh You can change the location during install but it must be in You're home dir or above.

  • Setting for example log files in a own created path example:
  • /Users/alfred/logs is allowed (the path Must well exist !!)
  • /private/var/logs is not allowed !!!

After Installation there will be a install.log file in

  • $HOME/Library/Logs/login-logout-script-install.log

Manual Install :

There are two files:

  • login-logout-script.plist
  • login-logout.sh: bash shell script

Install

Customize the login-logout-script.plist: according explanation in file.

Then copy the file login-logout-script.plist to $HOME/Library/LaunchAgents/

Customize the login-logout.sh to you're needs place it in $HOME/Library/Scripts .

  • Make script executable.
  • chmod 755 $HOME/Library/Scripts/login-logout.sh

To start the login logout service

  • open terminal
  • type : launchctl load -w ~/Library/LaunchAgents/login-logout-script.plist

To stop the login logout service

  • open terminal
  • type : launchctl unload -w ~/Library/LaunchAgents/login-logout-script.plist

The script will be started at every user login. Stopped on user logout. If you only wan't to load it manually set the key RunAtLoad into plist to false.

  • then start manually :
  • launchctl start LOGIN.LOGOUT.SERVICE
  • to stop
  • launchctl stop LOGIN.LOGOUT.SERVICE

After changing file login-logout.sh

unload and reload the service in order to have changes directly applied

  • open terminal
  • type : launchctl unload -w ~/Library/LaunchAgents/login-logout-script.plist
  • type : launchctl load -w ~/Library/LaunchAgents/login-logout-script.plist

Alternatively just logout,login,logout,login and You're changes should be in effect.

Links

macos-script-login-logout's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.