Skip to content

Commit

Permalink
update applescript for macOS 12 real
Browse files Browse the repository at this point in the history
  • Loading branch information
Yang-Xijie committed Oct 30, 2021
1 parent a6e908a commit 5f2b73d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
10 changes: 6 additions & 4 deletions InputSourceSwitcher.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
4880B5362683819300D53186 /* Shortcuts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shortcuts.swift; sourceTree = "<group>"; };
4880B53926838FC800D53186 /* Applesripts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Applesripts.swift; sourceTree = "<group>"; };
48860FC726845485002A5487 /* VersionAndBuildNumber.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VersionAndBuildNumber.swift; sourceTree = "<group>"; };
4892A68F272D1F5600D6E017 /* UpdateLog.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = UpdateLog.md; sourceTree = "<group>"; };
489B885326BD2EE20090DC8D /* Notificatioins.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notificatioins.swift; sourceTree = "<group>"; };
48CE6B682682611D00B1A186 /* AboutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutView.swift; sourceTree = "<group>"; };
48DA10442681781500A3D537 /* Source Switcher.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Source Switcher.app"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -107,6 +108,7 @@
48DA10462681781500A3D537 /* InputSourceSwitcher */,
4831FBDE2683AA0700D6C6F8 /* LICENSE */,
48DA10592681925400A3D537 /* README.md */,
4892A68F272D1F5600D6E017 /* UpdateLog.md */,
48DA10452681781500A3D537 /* Products */,
);
sourceTree = "<group>";
Expand Down Expand Up @@ -376,7 +378,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_ASSET_PATHS = "\"InputSourceSwitcher/Preview Content\"";
DEVELOPMENT_TEAM = C4W6UUH267;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -387,7 +389,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.2.2;
MARKETING_VERSION = 1.3;
PRODUCT_BUNDLE_IDENTIFIER = com.yangxijie.SourceSwitcher;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -403,7 +405,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_ASSET_PATHS = "\"InputSourceSwitcher/Preview Content\"";
DEVELOPMENT_TEAM = C4W6UUH267;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -414,7 +416,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.2.2;
MARKETING_VERSION = 1.3;
PRODUCT_BUNDLE_IDENTIFIER = com.yangxijie.SourceSwitcher;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
3 changes: 1 addition & 2 deletions InputSourceSwitcher/APP/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import SwiftUI
struct ContentView: View {
@ObservedObject var MyInputSources = InputSourcesModel()

// Show About if user open the app for the first time or update the app.
@State var isShowingAbout: Bool = UserDefaults.isFirstLaunchOfNewVersion() ? true : false
@State var isShowingAbout: Bool = false

var body: some View {
let frameHeight = CGFloat(100) + CGFloat(MyInputSources.inputSources.count * 30) // This formula is revived from experiments on MacBook Pro 13', whose display is scaled at 1680 * 1050.
Expand Down
16 changes: 12 additions & 4 deletions InputSourceSwitcher/Applescripts/Applesripts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,19 @@ func UseApplescriptToGetSystemInputSourcesInMenubar() -> [InputSource] {

func UseApplescriptToSwitchInputSource(to inputSourceName: String) {
let applesript = """
tell application "System Events"
tell process "TextInputMenuAgent"
click menu item "\(inputSourceName)" of menu 1 of menu bar item 1 of menu bar 2
click menu bar item 1 of menu bar 2
ignoring application responses
tell application "System Events"
click menu bar item 1 of menu bar 2 of application process "TextInputMenuAgent" of application "System Events"
end tell
end ignoring
delay 0.1
do shell script "killall 'System Events'"
delay 0.1
tell application "System Events"
launch
click menu item "\(inputSourceName)" of menu 1 of menu bar item 1 of menu bar 2 of application process "TextInputMenuAgent" of application "System Events"
end tell
"""

Expand Down
5 changes: 4 additions & 1 deletion UpdateLog.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# <#Title#>
# Update Log

## v1.3

* Update the applescript for `macOS 12 Monterey` to change input sources in `Applescripts.swift`. The new method is a little bit slower than before. Check more at <https://github.com/Yang-Xijie/InputSourceSwitcher/issues/15>.

0 comments on commit 5f2b73d

Please sign in to comment.