.com.unity Forums

.com.unity Forums (http://forum.shrapnelgames.com/index.php)
-   Scenarios, Maps and Mods (http://forum.shrapnelgames.com/forumdisplay.php?f=146)
-   -   Applescript PBEM support (http://forum.shrapnelgames.com/showthread.php?t=32709)

Psientist January 8th, 2007 08:08 PM

Applescript PBEM support
 
For us Mac users who host PBEM games - I kludged an applescript to create a drag-and-drop utility that the host (on an OSX Mac) can use to automatically send a PBEM file out to all of her/his players. Since I didn't add much, I leave the original author's credits intact:

Quote:


(* Send Attachment Droplet 1.2 by Joel Swenson, Copyright © 2006
Free for personal use
Modified and expanded version of Apple sample code "Create New Message", Copyright © 2002 Apple Computer
Version History:
1.2 More efficient script, identical functionality.
1.1 Available as a script, instead of application, so that it is more easily editable by other users. Must be saved as an application for droplet function to work.
Added "on run" functionality, prompting user to choose a file to attach.

1.0 Original release
*)
global theSender, theBody, theSubject, theAttachment

on open theFiles
repeat with oneFile in theFiles
tell application "Finder"
set filePath to POSIX path of oneFile
set theAttachment to filePath
end tell
makeMessage()
end repeat
end open

on run
set oneFile to choose file
tell application "Finder"
set filePath to POSIX path of oneFile
set theAttachment to filePath
set theSubject to name of oneFile
end tell
makeMessage()
end run



on makeMessage()
set theBody to "File Attached:"

set theSender to "hostemail@someplace.com" -- edit this line to match the email address of the host.
-- this must be a valid account in your mail.app program!
set theSubject to "Dominions 3 PBEM Game File" -- change this as desired

tell application "Mail"
set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return}
tell newMessage
set visible to true
set sender to theSender
make new to recipient with properties ("player1@otherplace.com") -- change this to one of your players' valid email address
-- make new cc recipient with properties ("player2@otherplace.com") -- add as many of these as you have players!
tell content
make new attachment with properties {file name:theAttachment} at after the last paragraph
end tell
end tell
send newMessage
end tell
end makeMessage


save the script as a run-only app, and put it where it's convenient to access for drag-and-dropping your game file after you have finished hosting a turn. It will automatically open Mail.app, create an email with all appropriate addressees, and send it...saving you a few steps at least.

My test file works, but let me know if you run into errors. I'll probably be working on an applescript to reside inside Mail.app for saving and filing the return gamefiles from the players.

good luck!

PashaDawg January 11th, 2007 10:16 AM

Re: Applescript PBEM support
 
Thanks for the script! I know Ygorl also has some apple scripts that he created.

I have a simple OSX "Tiger" workflow using Automator that backs up the current turn, creates emails to all players and attaches the appropriate .trn file to each player. I'd be happy to share it. It's nothing fancy but it makes hosting a lot quicker.

Keeping track of player turns is easy by using smart folders in Mail.

Psientist January 11th, 2007 11:48 PM

Re: Applescript PBEM support
 
Hey, that sounds like an even slicker way to manage it than my idea. I'd appreciate it if you posted your automator script!

PashaDawg January 12th, 2007 01:47 AM

Re: Applescript PBEM support
 
Ok! I will do it over the weekend. I will need to create a "blank" version because I tailor it for each PBEM game in question (e.g., by creating the template for each player's email, specifying where to save back ups for the particular game, etc.)

PashaDawg January 14th, 2007 04:29 PM

Mac OSX Automator Workflow for PBEM
 
1 Attachment(s)
Here is a template using Mac OSX Automator to streamline PBEM hosting a bit. After the turn is hosted, I run this workflow. It will back up the current turn and create the emails with proper attachments for the various players.

Obviously, a specific workflow must be first tailored to the needs of each game but that is easily done.

Psientist January 14th, 2007 08:00 PM

Re: Mac OSX Automator Workflow for PBEM
 
I've been playing around with that, and your script like a great start. I wanted to add an automated turncounter, so I came up with this kludge that built upon your ideas.

Start with a file selection Automator action which specifies a text file which records the turn number, and feed that into the following applescript, you can read the turn number into a variable in Automator and increment it:

Quote:


property theAttachmentPath : (path to "desk") as string

on run {input, parameters}
set mailrecipient to "player@email.com"
set gameattachmentpath to "/Users/youraccount/dominions/savedgames/gamename/early_vanheim.trn"
set mailsubject to "Dominions 3 Game: Turn #" -- turn number will be appended automatically here
set mailcontent to "Here is your most recent game turn. Please save this to your dominions3>test2 directory." & return & return

set theAttachmentPath of me to (item 1 of input as string)
set p to POSIX path of theAttachmentPath
set theFile to POSIX file p
set turnnumber to do shell script "cat " & p
set turnnumber to (turnnumber + 1)
do shell script "echo '" & turnnumber & "' > " & p
set fileAttachThis to POSIX path of gameattachmentpath
set mailsubject to mailsubject & " " & turnnumber


tell application "Mail"
activate
set this_message to make new outgoing message at end of outgoing messages with properties {visible:false}
tell this_message
make new to recipient at end of to recipients with properties {address:mailrecipient}
set the subject to mailsubject
set the content to mailcontent
make new attachment with properties {file name:gameattachmentpath} at after the last word of the last paragraph
end tell
send this_message
end tell
HideMe()
end run


on HideMe()
tell application "System Events"
set visible of process "Mail" to false
end tell
end HideMe



As far as I know, Automator will not allow multiple inputs into an action (I'm an Automator noob, I could be wrong), so unfortunately the filename for the turn incrementer file and other variables have to be set inside the applescript as opposed to feeding nicely into a Send Mail action.

PashaDawg January 15th, 2007 08:20 PM

Re: Mac OSX Automator Workflow for PBEM
 
Nice. I don't know much about Applescript. But, you can build apple scripts into Automator.

I have not spent a lot of time working on this, but the one thing that is still laborious is putting the turn number at the end of each email's subject line. That turn number is important for keeping track of various turn emails (which go into a smart mailbox in Mail for each particular game).

Do you know of a way to insert a text "variable" into a line of text, etc.?

In any case, it still reduces that hosting time significantly. I don't have to create or address the emails, and the attachments are made automatically.

Maybe Ygorl has some ideas, too. I know he created some Applescript stuff.

Pasha

Psientist January 16th, 2007 12:35 PM

Re: Mac OSX Automator Workflow for PBEM
 
Lucky you asked! The most recent version I posted has that capability built in (keeping track of turn numbers, posting them to the subject line!).

What I'm trying to research is a way to applescript Mail rules so that when a player sends a turn, the script automatically moves the attachment turnfile to a specified folder, and notifies a webpage that keeps track of who has sent, and received which turns in a game. I have found in past PBEM games (civilization, warlords) that player confusion over this is the source of most delays.

I know how to script the website part, but my initial forays into the mail rule applescript is going unexpectedly haltingly.

Gandalf Parker January 16th, 2007 01:40 PM

Re: Mac OSX Automator Workflow for PBEM
 
On linux there are programs which "sort" incoming mail to "folders" for spam handling and such. You might look for applescript examples to do that. You should be able to modify one to handle a specific type of subject line and sort it out.

For the notify web-page part I went the lazy route by having the webpage display the actual files. Or in this case, possibly something that lists the emails that are in that incoming game folder that the first routine sent them off to.

PashaDawg January 16th, 2007 02:45 PM

Re: Mac OSX Automator Workflow for PBEM
 
Yes. I am stuck sending "status" emails to the players in between turns as a reminder and as a safeguard in case any players think they sent their turn (or if I never received the turn). A website might be nice, or a script that would automatically figure out which players have played and send an email. I think a reminder email is helpful to players. It would be to me. Dreams, dreams, dreams. http://forum.shrapnelgames.com/images/smilies/happy.gif

Gandalf Parker January 16th, 2007 04:43 PM

Re: Mac OSX Automator Workflow for PBEM
 
PashaDawg:
Is that a mac need? linux? windows?

PashaDawg January 16th, 2007 07:29 PM

Re: Mac OSX Automator Workflow for PBEM
 
Hi Gandalf:

I have a Mac. I have an automator "workflow" that I posted earlier. It makes hosting PBEM a lot faster. It now takes less than 5 minutes to host the turn and get all the emails out. But it could be quicker if I did not need to manually add the turn number to each email subject line. I am not cranky, but why not do even better! http://forum.shrapnelgames.com/images/smilies/happy.gif

Maybe I will take a look at some of the websites about using Automator.

Pasha

Gandalf Parker January 16th, 2007 08:43 PM

Re: Mac OSX Automator Workflow for PBEM
 
If the game switch tells it to output a scoreboard file then you can get the turn from that.

Or you can do a check of the .2h files with
dom3 --verify gamename
and the turn number will be in the tiny .chk file

PashaDawg January 16th, 2007 10:38 PM

Re: Mac OSX Automator Workflow for PBEM
 
Hmm. A little too advanced for my lawyer brain. http://forum.shrapnelgames.com/images/smilies/happy.gif

Psientist January 17th, 2007 07:35 PM

Re: Mac OSX Automator Workflow for PBEM
 
PashaDawg, check my code - I've implemented the Turn Number option already.

It's the incoming mail-sorter and web-based status page that I'll be working on.

Gandalf, i've used the *nix mail sorters. I don't think it will work on the OSX, since the Mail.app program establishes a direct pop3 connection to the mail server, bypassing any *nix mail processing (e.g., the mac is not being used as a mail server). I'm sure there's a way to do it in applescript with mail rules, I just haven't had time to play with it.


All times are GMT -4. The time now is 10:32 AM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2025, Shrapnel Games, Inc. - All Rights Reserved.