Sometimes I want to automate some tasks using bash scripts. Even if that means I have to execute a Windows application, especially when the application exists only on Windows. If you have CrossOver and don’t want to get a wine installation (through Homebrew or MacPorts) too, this might work for you as well. I happen to make it work with a CrossOver installation.

I want to show you the steps I needed to create a shell script.

# Start CrossOver, otherwise the X11 server from CrossOver wasn't found when executing wine (from CrossOver)
open -a CrossOver

# Now quite a few variables should be set, so wine should find everything it needs.
export 'DYLD_FALLBACK_LIBRARY_PATH'='/Applications/CrossOver.app/Contents/SharedSupport/X11/lib:/Users//lib:/lib:/usr/lib:/usr/X11/lib'
export 'FONTCONFIG_ROOT'='/Applications/CrossOver.app/Contents/SharedSupport/X11'
export 'FONTCONFIG_PATH'='/Applications/CrossOver.app/Contents/SharedSupport/X11/etc/fonts'
export 'FONT_ENCODINGS_DIRECTORY'='/Applications/CrossOver.app/Contents/SharedSupport/X11/lib/X11/fonts/encodings/encodings.dir'
export 'VERSIONER_PERL_PREFER_32_BIT'='yes'
export 'CX_BOTTLE_PATH'='/Users//Library/Application Support/CrossOver/Bottles'
export 'CX_ROOT'='/Applications/CrossOver.app/Contents/SharedSupport/CrossOver'
export 'CX_BOTTLE'='winxp' # <-- You can set the bottle to execute the .exe in, this is helpful when the .exe has some dependencies!

# Determine the DISPLAY variable since this can change sometimes
export 'DISPLAY'=':'$(defaults read com.codeweavers.CrossOver Display)

# Now we extend the PATH variable and put the bin from CrossOver at the first possible location, to not collide with an 
# additional wine installation you might have
export 'PATH'='/Applications/CrossOver.app/Contents/SharedSupport/CrossOver/bin:'$PATH

# Now we can start the application however we ant
wine <path to .exe> <parameters>

Just replace the placeholder <path to .exe> and <parameters> with your application and you’re set to go.