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/'
export 'FONTCONFIG_ROOT'='/Applications/'
export 'FONTCONFIG_PATH'='/Applications/'
export 'FONT_ENCODINGS_DIRECTORY'='/Applications/'
export 'CX_BOTTLE_PATH'='/Users//Library/Application Support/CrossOver/Bottles'
export 'CX_ROOT'='/Applications/'
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/'$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.