As @LeeJoramo suggested, you can use Keyboard Maestro and some AppleScript to turn on the desired layout when switching to a certain app. For example, here's a KM macro that sets my keyboard layout to "Greek" when I switch to TextMate:

![enter image description here][1]


  [1]: http://i.stack.imgur.com/E8SLO.png

The script, borrowed from [this StackOverflow answer](http://stackoverflow.com/a/23741934/989121):

    tell application "System Events" to tell process "SystemUIServer"
    	tell (menu bar item 1 of menu bar 1 whose description is "text input")
    		select
    		tell menu 1
    			click (first menu item whose title contains "Greek")
    		end tell
    	end tell
    end tell