The forum

Diablo 3 - Script for Multi-Monitors

Automatically disable and then re-enable your secondary display

Author Replies
tnt533 Friday 10 August 2012 at 4:31
tnt533Anonymous

Heres a script I wrote today to disable my secondary monitor, start the game and then automatically re-enable it after the main Diablo II.exe process exits. Without the script you have to manually reconfigure your monitors every time you're done playing and it's a pain in the arse.

This script could very easily be modified to work with about any game or application on your system if need be.

If you're unfamiliar with dealing with scripts, heres how to make it work.

1. copy the entire script to a new text file on your desktop and save it as what ever you want. It doesn't have to have a .sh extension, this is Linux, right?!

2. right click on the file and select Properties from the context menu that pops up. Click on the Permissions tab and make sure the 'allow executing file as a program' box is checked. click ok. As an alternative you can open a terminal in the folder where the file resides and type 'chmod +x {filename}' without the ' or {} and accomplish the same thing.

3. right click the file again and open it with the text editor of your choice but avoid using "word processors" like open office writer because of the encoding they use on the text. For Ubuntu, gEdit is perfect. For Mint 13 try Pluma. Use a simple "Notepad" style editor.

4. Read all the comments, theres a lot of them to make it very self explanatory and adjust the script according to your system specifics.


Make sure to keep a backup of the original script in case your edits cause a malfunction.

5. Profit!

I'll put the entire script in the second post so theres no doubt what to copy and paste. Grab everything folks and enjoy!

Please remember that I am WAY NEW to bash scripts so if it's sloppy or could be done in 1 line of code instead of 5, send me an email and share your wisdom, don't flame in the thread. :) My email is in the script in the next post.

tnt533 Friday 10 August 2012 at 4:32
tnt533Anonymous

#############################################
# Diablo III Multi-Monitor Script
#
# This script was specifically
# designed to work with Daiblo 3
# installed on a Debian based disto
# with PlayOnLinux. It will disable
# your secondary monitor, launch the game
# and then re-enable your secondary monitor
# automatically when the main game process
# terminates. Please feel free to use, edit
# and redistibute this script all you want
# but I retain the rights to this code.
# Please do not redistribute this script
# without this section.
############################################

#!/bin/bash

## Turn off left display
# Use 'xrandr -q' at a terminal to find
# the proper names of your displays
# and subsitute in the first and last line
# of this script. My secondary display is CRT1.
# Yours likely will be different.
xrandr --output CRT1 --off

## Start Diablo 3
# This command was obtained through the
# properties dialog box of the shortcut
# created on the desktop by PlayOnLinux
/usr/share/playonlinux/playonlinux --run "Diablo III" %F

# Allow a few seconds for the process to get
# up and running before entering PID check
sleep 5 # <- Probably not needed

## Wait until launcher/game closes
# Do a 'whereis pidof' at a terminal
# to determine the location of the pidof
# executable on your system and change the
# script accordingly. Also, make sure that
# your PlayOnLinux wine prefix directory is
# located within your path or you will possibly
# have to use absolute path statements in the
# code below.
#
# Blizzard Launcher check
u=`/bin/pidof Blizzard\\ Launcher.exe`
while [ -n "$u" ]
do
u=`/bin/pidof Blizzard\\ Launcher.exe`
done
## Diablo III main process check
t=`/bin/pidof Diablo\\ III.exe`
while [ -n "$t" ]
do
t=`/bin/pidof Diablo\\ III.exe`
done

# Reenable left display after game
# process ends.
xrandr --output CRT1 --auto --right-of DFP9

###################################################
# Final Thoughts.
# You can also modify and incorporate the code
# below which I obtained from this forum post;
# https://bbs.archlinux.org/viewtopic.php?id=99550
# to automatically check if compiz is running
# and switch to the window manager of your choice
# and then back again at the end of the script.
# I had issues with compiz flaking out after the
# script terminated. Your mileage may vary. 
##################################################
# if [ $(dbus-send --print-reply --type=method_call --dest=org.freedesktop.compiz /org/freedesktop/compiz/dbus/screen0 org.freedesktop.compiz.list 2>/dev/null | wc -l) -eq 0 ]; then
# metacity --replace &
#else
# compiz --loose-binding --replace ccp &
#fi

Edited by tnt533

This site allows content generated by members, and we promptly remove any content that infringes copyright according to our Terms of Service. To report copyright infringement, please send a notice to dmcayonlinux.com