Help with external scripts for mac

Mrfred

New member
Hey, I have a script that I wanted to test its efficiency with, so I have a few multi accounts, and I have the script set to login. What I wanted to know was if there are any big mac scripters out there that could help me automatically log in to each account and logout when it was finished log the next account in?

I tried some scripting with applescript, but I have never used it before, and the keystroke function didnt seem to work for the login box. I havent really done much with external scripting. If someone could make a script or describe how to make one (not necessarily with applescript) I would greatly appreciate it. Thanks

Mrfred
 

Theraze

Active member
Logout is easy... it's a CLI script command. Not sure if it's possible to login as an internal script command though... don't think so.
 

Grotfang

Developer
Use cron.

Sounds like you are basically there. Your start-up script should read something like this:

Code:
login characterOne
call myScript.ash
logout
login characterTwo
call myScript.ash
logout

Remember, myScript.ash can handle different usernames using my_name() or my_id(). Alternatively, call a different script for each character. The second advantage of this method is you can pipe the output to a single file if you wish to check your script for efficiency between characters. Re: applescript... I'm sure you could produce something functional. But since you say you have a login file (and the script set up) this method is one line on your crontab (or typed into the terminal). Why waste time and effort?
 
Last edited:

Mrfred

New member
Thanks for the quick feedback

@Theraze - I know how to logout with a script, I just wanted to know if it was possible to determine exactly when the script finished. I imagined that would be easier if the external program was set to give kol mafia a command to close, which would take place after the script finished, but I am open to suggestions.

@Grotfang - I have never used cron before.... it sounds like it was made for linux. I downloaded it from here, for the mac, but as I mentioned, I am not really familiar with this sort of thing. Any info you could give me as to how to program it just to even send the logon and logoff commands to kol mafia would be helpful. I have my scripts set to run on login for the characters that I want, so I dont even have to call the script. Meanwhile I will play around with the program. Thanks!

@slyz - Me too
 

Veracity

Developer
Staff member
Cron was made for Unix, long before Linux was created. Linux and MacOS X are both varieties of Unix, and can thus run Unix utilities.
 

Mrfred

New member
Cron was made for Unix, long before Linux was created. Linux and MacOS X are both varieties of Unix, and can thus run Unix utilities.

Alright........ I don't even know how it works... If you could tell me how to input commands to run mafia and login/logout, that would be helpful......
 

Grotfang

Developer
You downloaded cron? I would have assumed it came with the system. Unless you are talking about a GUI front-end, in which case I can't give you any specific guidance. What I can do is talk you through the terminal. My advice is coming from a linux system, but as Veracity said, it's all the same for our purposes :)

Open up your terminal and type:

Code:
crontab -e

Type in the time you want your task to happen at, using the format m h d m w c

m = minute
h = hour
d = day of month (1 to 28, 30 or 31)
m = month
w = day of week (0-6 starting on Sunday)
c = command

For example, my clan bot has a crontab line:

Code:
50 19 * * * /home/Grotfang/rungsl start

This means that at 1950 (7.50pm) every day (* are wildcards, as one might expect) he executes /home/Grotfang/rungsl start (a service I have set up that handles the bot).

The simplest command to initiate mafia would be:

Code:
java -jar /home/<dir>/KoLmafia.jar <script>.txt

<dir> is your path to the KoLmafia.jar file, <script>.txt is your login script. You would have to finish that script with "exit" instead of "logout" to ensure the process properly finishes. So, if you wanted to run mafia each day with a login script called login.txt at, let's say, 8.15pm, you could type the following into crontab:

Code:
15 20 * * * java -jar /home/<dir>/KoLmafia.jar login.txt

Any clearer?

EDIT: Whoops! Forgot to mention... when you type in crontab -e you may well find it opens in vi. To edit stuff, key i, type what you want, then hit escape. Typing :wq will save and exit. Or better yet, look vi up -- there is a lot you can do with it and it's a useful editor.
 
Last edited:

Mrfred

New member
Alright, thanks a lot for the clarification. You were right in that I did download a gui. That was after I couldnt find the right command to open cron, lol. I have yet to open KoLmafia using terminal, but I think it just has to do with the directory, or the name of mafia. I am sure to get it sometime soon. I will reply when I do. Thanks a lot


EDIT: The login.txt would just be the code from your previous post and would be in the same directory as mafia?

EDIT2: The GUI told me that the command /usr/bin/open /Applications/KoLmafia-14.1.app would open kolmafia, and it worked in the gui..... I tried adding the login.txt to the end but it screwed it up, also I don't think that line worked in terminal, so........ *sigh*
 
Last edited:

slyz

Developer
EDIT: The login.txt would just be the code from your previous post and would be in the same directory as mafia?
I think it would need to be in Mafia's /script folder. And I guess it doesn't need to be .txt.

EDIT2: The GUI told me that the command /usr/bin/open /Applications/KoLmafia-14.1.app would open kolmafia, and it worked in the gui..... I tried adding the login.txt to the end but it screwed it up, also I don't think that line worked in terminal, so........ *sigh*

Don't you need to launch KoLMafia with java? The command line should be what Grotfang posted:
Code:
java -jar /home/<dir>/KoLmafia.jar <script>.txt
although that's for a daily build. For a .exe version, maybe you should skip the -jar option.
 

Mrfred

New member
Alright, good news, I finally found out what I was missing in my applescript. So I finally got it to work, and I will be able to test it after rollover. Thank you for all the help, and if you want to keep teaching me cron that would be fine with me, although I dont need it anymore at the moment. Once again, thanks a lot. Even though I was not skilled enough to use it for my automation, it still taught me a lot I didnt know. THanks.
 

Grotfang

Developer
I'm glad you got things sorted in the end.

I think it would need to be in Mafia's /script folder. And I guess it doesn't need to be .txt.

You are right on both counts. The .txt is superfluous. I like to use it as it helps me distinguish between ash and cli quickly, but frankly, a present vs absent suffix would be equally as useful. Or maybe call it <script>.cli.

As for using anything other than the .jar -- don't. Use the daily builds and do things properly :p
 
Top