I am by no means an AppleScript expert (in fact, this is the first one I've written), but this is working for me and consistently mapping the right port and doing the right things.
== BEGIN ==
set app_name to "Transmission"
set the_pid to (do shell script "ps ax | grep " & (quoted form of app_name) & " | grep -v grep | awk '{print $1}'")
Comments
== BEGIN ==
set app_name to "Transmission"
set the_pid to (do shell script "ps ax | grep " & (quoted form of app_name) & " | grep -v grep | awk '{print $1}'")
if the_pid is not "" then do shell script ("kill -9 " & the_pid)
--Gets the IP address of interface Name of Interface
set myIP to do shell script "ifconfig utun1 |grep 'inet '|cut -d ' ' -f 2"
set client_id to (do shell script "head -n 100 /dev/urandom | shasum -a 256 | tr -d ' - '")
set port_number to (do shell script "curl http://209.222.18.222:2000/?client_id=" & client_id & " | awk -F: '{print $2}' | sed 's/.$//' 2>/dev/null")
log myIP
log client_id
log port_number
-- Write your Correct Starting Paramters to ~/Library/Preferences/org.m0k.transmission.plist
do shell script "defaults write ~/Library/Preferences/org.m0k.transmission.plist BindAddressIPv4 " & myIP & ""
do shell script "defaults write ~/Library/Preferences/org.m0k.transmission.plist BindPort " & port_number & ""
-- Activate Transmission
tell application app_name to activate
== END ==
Obviously no warranty, no support, all I did was hack this together in about 45 minutes. Feel free to use/improve on this as you like.