By having a script located in a subfolder startup scripts
of e.g. the user script folder, one can have a script run at startup. What I would like to achieve now is having the script determine whether it is run due to that startup (and e.g. create menu items for its functions) or whether it was run manually (and then perform its main function, not caring about its startup function). How can this be achieved?
Asked
Active
Viewed 312 times
0

Tobias Kienzler
- 25,759
- 22
- 127
- 221
1 Answers
3
Given that the script is located within the Startup Scripts Folder:
var scriptKind = (app.activeScript.parent.name=="Startup Scripts")? "startup":"normal";
alert( scriptKind );

Loic
- 2,173
- 10
- 13
-
2Ah. Just checking the folder. Awesome. I was thinking about creating a targetengine and have a global flag that gets set on startup. But this is much simpler. – fabianmoronzirfas Jun 22 '16 at 05:35
-
Sounds like I've been overthinking this m-/ Of course I can then symlink the same script both in the startup and regular folder... Though @fabiantheblind's idea also makes sense, especially since for not recreating menus you need to keep track somehow anyway... – Tobias Kienzler Jun 22 '16 at 06:15
-
Simple yet possibly wrong if script is placed as shortcut or inside subfolder. So it's very contextual. – Loic Jun 22 '16 at 06:35
-
Indeed, e.g. it turns out `app.activeScript` returns the real script location when a Windows `.lnk` is used... In that case I'll have to stick to @fabiantheblind's suggestion – Tobias Kienzler Jul 06 '16 at 14:17
-
You also have access to $.fileName that returns the full path of the current script if saved. – Loic Jul 06 '16 at 14:34