Launching applescript .scpt at startup

thelordymir
New Contributor II

I was wondering if it is possible for casper to launch a .scpt file after reboot. I've created an entire install script that sets up login hooks, tweaks settings, etc etc and need it to run after the initial reboot following the imaging process.

Last year I used a shell script to point to my compiled .scpt in .app form and start it that way, but with Mavericks it seems this produces a lot of strange errors that are probably permission based.

The .scpt works fine if I toss it on the Desktop, use composer to create a dmg, and then run it off desktop but I would like to have it as automated as possible.

7 REPLIES 7

gregneagle
Valued Contributor

It might be possible, but it's likely not to work correctly. Most AppleScripts will not run correctly at the loginwindow.

It's working when you manually run it because there's a user logged in and you are running it under a GUI user's context.

You'd be much better off if this was a shell script or Python script.

acdesigntech
Contributor II

+1

You should stay away from applescripts. Apple is making it harder and harder to use .scpts in recent OSes through multiple security measures - blocking gui scripts at the login window, screen lock window, changes in the accessibility framework in 10.9, etc.

Plus, Casper has issues with applescripts unless you're extremely careful about running them under the correct user account (ie: logged in user) and even then it sometimes has issues.

Your best bet is to port your applescript code to shell, perl, python, or something else and stick with that. Plus, these scri[pting languages are much more powerful and portable to other *nix OSes than Applescript.

thelordymir
New Contributor II

Yeah I want to convert it, but was running into a few issues here and there setting up the mouse preferences and applescript was a easy work around. That said I plan to convert the thing to a shell script this summer to just make it so much easier.

bentoms
Release Candidate Programs Tester

@thelordymir, other than the above. Are you using login/out hooks in the JSS.

These will override what you're trying to do.

Also, have you looked at moving the settings your scripting to managed preferences &/or config profiles?

thelordymir
New Contributor II

Not using any hooks in the JSS.

Where abouts does Casper execute scripts set as "After" in the priority listing? I created a script to enable autologin but writing to the plist. It works properly in all of my testing, but when I set it as part of my config it never seems to execute. Setting it as "Before", "After" or "Reboot", nothing seems to execute the script.

Permissions are set to 777 on it, I get no errors. Not sure where it's hanging up.

bentoms
Release Candidate Programs Tester

@thelordymir, maybe instead.. Run via a launchAgent?

thelordymir
New Contributor II

Thanks for the suggestion @bentoms

Seems to be working properly, going to test it out on a few different machines. Just even more reason I need to convert this all to a python/shell script haha.