0

I've created a bash script which does some complex stuff, including some bits of Applescript which involves clicking pop ups, its to run on every new account created on the machine to set up some browser extensions for users (Adblock etc)

The script runs when manually invoked just fine, but when put as a LaunchAgent is erratic at best. It seems to run whilst the create account login/password screen is up - it opens a welcome PDF for a start off and sometimes when you log in, preview is already open without the file.

Othertimes you log in and nothing happens for a good 50 seconds. Occasionally its behaviour is erratic too.

The script needs to run as a launchagent as it runs once per new account - the script actually deletes the launchagent plist at the end so it can't run again. Is there anyway to delay the running of the script to have it start once the desktop is fully loaded? Perhaps once the dock has appeared. I'm going to assume its trying to run too early, it can't open Preview or Safari, it tries to delete the plist which is in use and then just ends up in a confused loop. Obviously not the cleanest way to run.

realdannys
  • 1,383
  • 1
  • 12
  • 18
  • Have you tried letting it `sleep` for a period of time as the beginning of the script? – user3439894 Mar 24 '15 at 19:23
  • I haven't, but i'm not sure if that would help too much as it could just mean it doesn't run for a long time after the user creates their account. They could be creating their account anything between 1 minute and 10 minutes really. I wonder if there is any other way to run per user scripts specifically as the last part of the desktop loading. – realdannys Mar 24 '15 at 19:37
  • Maybe a loginhook might be a better way to go for this? Although i'm not sure at what point they run either, but presumably once the user is full logged in and not just when system resources are available ala launchagents? – realdannys Mar 24 '15 at 19:47

0 Answers0