Help with AppleScript to switch language in

Hello all,

Hoping some kind soul can help me out!

I often write emails in a 2nd language, and need to switch from the default OSX spelling language, to this 2nd one.
It gets a bit tedious having to go through the menus each time, and was hoping I could compile an AppleScript, and then have Keyboard Maestro trigger it with a [typed string].

I found a 2009 script example, and made minor(?) adjustments, to try and get the menu selection correct. But it’s not working properly. Would really appreciate it if someone could have a look below, and advise as to where my problem might be??

Many thanks!

tell application "Mail"
	tell application "System Events"
		tell application process "Mail"
			set frontmost to true
				click menu item "Show Spelling and Grammar" of menu "Spelling and Grammar" of menu "Edit" of menu bar 1
				set fen to window "Spelling and Grammar"
				click pop up button 1 of fen
				set lemenu to menu 1 of pop up button 1 of fen
				if selected of menu item "English (South Africa) (Library)" of lemenu is true then
					click menu item "English (South Africa) (Library)" of lemenu
					click menu item "Afrikaans (Library)" of lemenu
				end if
				click button 1 of fen
			on error
				beep 2
			end try
		end tell
	end tell
end tell

Model: MBP
AppleScript: 2.5
Browser: Safari 601.2.7
Operating System: Mac OS X (10.10)

Hey Cassady

Install Shane Stanley’s Bridge Plus Library, and this task becomes trivial.

use framework "Foundation"
use script "BridgePlus"
load framework

set availableInputSources to (current application's SMSForder's availableInputSourceIDs()) as list
set allAvailableInputSources to (current application's SMSForder's allAvailableInputSourceIDs()) as list

set langSwitchResult to current application's SMSForder's changeInputSourceTo:""
delay 0.1
set langSwitchResult to current application's SMSForder's changeInputSourceTo:""
delay 0.1
set langSwitchResult to current application's SMSForder's changeInputSourceTo:""


{ MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.11.1 }

Chris, appreciate the help.

I’ve downloaded it “ but silly question, where is it to be installed? Ran the compiler, and it said it couldn’t find BridgePlus script “ since I’ve obviously not put it in the right place: dropped the folder into the /Library/Scripts folder? Should it rather go in /Library/Scripts/Applications/System Events?

Secondly, I presume the above is changing the “keylayout” to whatever the default options were, that came bundled with OSX? The language/spelling ‘dictionaries’ I’m trying to use, where installed after the fact “ so not sure if they would have the option included that I need?

It seems that you missed what is carefully writen in the page pointed by ccstone :

BridgePlus should be installed with any other script libraries in a folder called Script Libraries inside your ~/Library folder. You can also embed it directly in script applications and bundles; see below.

I add that you may choose to install it in : /Library/Script Libraries
As you ask about that I guess that you will have to create the folder.

Yvan KOENIG running El Capitan 10.11.1 in French (VALLAURIS, France) jeudi 3 décembre 2015 19:05:07

Probably not. It changes the keyboard language, and relies on the fact that that changes the preferred language. But if you have no keyboard input source for the other language, it’s not going to work.

Thanks Yvan, I didn’t miss it - but as you correctly surmised, since I didn’t have such a folder, I put it with the rest - thinking my Folder System was simply different, and it not occurring to me that I need to actually ‘create’ the folder.

I will do so, and drop the script file in their, for future use.

Shane - many thanks (for the reply, and everything done over at macosxautomation!!).

Figured as much - will keep playing around with it then, to see if I can work something out.