Clean up applescripts and some redundant code