-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dispaly-switch): added AppleScript for toggling display configur…
…ations (#12) Included README with usage instructions and prerequisites. #### Motivation and context <!--- Why is this change required? --> #### Checklist: - [x] I covered my changes with tests
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Display Configuration Toggle Script | ||
|
||
This AppleScript allows you to toggle between two different display configurations on macOS. It is designed to be used | ||
with the `displayplacer` command-line tool. | ||
|
||
## Prerequisites | ||
|
||
- **`displayplacer`**: Ensure you have `displayplacer` installed. You can install it via Homebrew with the following | ||
command: | ||
|
||
```bash | ||
brew install displayplacer | ||
``` | ||
|
||
## Script Overview | ||
|
||
### The script provides two display configurations: | ||
|
||
1. Initial Configuration (example): | ||
• Display 1: id:37D8832A-2D66-02CA-B9F7-8F30A301B230 at 2056x1329 resolution, 120Hz, 8-bit color depth, enabled, scaling on, origin at (0,0). | ||
• Display 2: id:9261071D-C9FC-4476-9F8D-BC7B52CF4071 at 2560x1440 resolution, 60Hz, 8-bit color depth, enabled, scaling on, origin at (2056,0). | ||
2. Alternate Configuration (example): | ||
• Display 1: id:9261071D-C9FC-4476-9F8D-BC7B52CF4071 at 2880x1620 resolution, 60Hz, 8-bit color depth, enabled, scaling on, origin at (0,0). | ||
|
||
### Using the Script | ||
|
||
1. Open Script Editor: | ||
• Open the Script Editor application on macOS. | ||
2. Paste the Script: | ||
• Copy and paste the provided AppleScript code into Script Editor. | ||
3. Save the Script as an Application: | ||
• Go to File -> Export. | ||
• Set File Format to Application. | ||
• Choose a name (e.g., “Display Config Toggle”) and location for your app, then click Save. | ||
4. Grant Necessary Permissions: | ||
• Open System Preferences -> Security & Privacy -> Privacy tab. | ||
• Select Full Disk Access or Automation, then add your new app if it’s not listed. | ||
5. Run the Application: | ||
• Double-click the app to run it. You will see a dialog prompting you to choose between the “Initial” and “Alternate” configurations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
-- Global Constants | ||
property BES_DISPLAYPLACER_PATH : "/opt/homebrew/bin/displayplacer" | ||
property BES_DEFAULT_PROPRESENTER_CONFIG_COMMAND : BES_DISPLAYPLACER_PATH & " 'id:4F494B73-B908-4053-8314-E259F924A0AA res:2560x1440 hz:60 color_depth:8 enabled:true scaling:on origin:(0,0) degree:0' 'id:98D31832-E235-4AAD-B122-81E6BC856D87 res:1920x1080 hz:60 color_depth:8 enabled:true scaling:off origin:(-1920,0) degree:0' 'id:8873492D-99CD-44AF-A7D0-F9C3F33212B8 res:1344x768 hz:60 color_depth:8 enabled:true scaling:off origin:(2560,0) degree:0'" | ||
property BES_POWERPOINT_CONFIG_COMMAND : BES_DISPLAYPLACER_PATH & " 'id:4F494B73-B908-4053-8314-E259F924A0AA res:2560x1440 hz:60 color_depth:8 enabled:true scaling:on origin:(0,0) degree:0' 'id:8873492D-99CD-44AF-A7D0-F9C3F33212B8+98D31832-E235-4AAD-B122-81E6BC856D87 res:1344x768 hz:60 color_depth:8 enabled:true scaling:off origin:(2560,0) degree:0'" | ||
|
||
property BES_ERROR_SETTING_INITIAL_CONFIG_MESSAGE : "Eroare: " | ||
property BES_ERROR_SETTING_ALTERNATE_CONFIG_MESSAGE : "Eroare: " | ||
property BES_ERROR_IN_USER_CHOICE_DIALOG_MESSAGE : "Eroare: " | ||
property BES_CHOOSE_DISPLAY_CONFIG_MESSAGE : "Alege configurația monitoarelor:" | ||
property BES_PRO_PRESENTER_CFG_BUTTON : "Pro Presenter - Extend Display & Stage" | ||
property BES_POWER_POINT_CFG_BUTTON : "PowerPoint - Mirror Display & Stage" | ||
property BES_OK_BUTTON : "OK" | ||
|
||
-- Function to set the initial configuration (Pro Presenter Display + Stage) | ||
on defaultProPresenterConfig() | ||
try | ||
do shell script BES_DEFAULT_PROPRESENTER_CONFIG_COMMAND | ||
on error errMsg number errNum | ||
display dialog BES_ERROR_SETTING_INITIAL_CONFIG_MESSAGE & errMsg & " (Error number: " & errNum & ")" buttons {BES_OK_BUTTON} default button BES_OK_BUTTON | ||
end try | ||
end defaultProPresenterConfig | ||
|
||
-- Function to set the alternate configuration | ||
on setPowerPointConfig() | ||
try | ||
do shell script BES_POWERPOINT_CONFIG_COMMAND | ||
on error errMsg number errNum | ||
display dialog BES_ERROR_SETTING_ALTERNATE_CONFIG_MESSAGE & errMsg & " (Error number: " & errNum & ")" buttons {BES_OK_BUTTON} default button BES_OK_BUTTON | ||
end try | ||
end setPowerPointConfig | ||
|
||
-- Prompt user for configuration choice | ||
try | ||
set userChoice to display dialog BES_CHOOSE_DISPLAY_CONFIG_MESSAGE buttons {BES_PRO_PRESENTER_CFG_BUTTON, BES_POWER_POINT_CFG_BUTTON} default button BES_PRO_PRESENTER_CFG_BUTTON | ||
|
||
if button returned of userChoice is BES_PRO_PRESENTER_CFG_BUTTON then | ||
defaultProPresenterConfig() | ||
else if button returned of userChoice is BES_POWER_POINT_CFG_BUTTON then | ||
setPowerPointConfig() | ||
end if | ||
on error errMsg number errNum | ||
display dialog BES_ERROR_IN_USER_CHOICE_DIALOG_MESSAGE & errMsg & " (Error number: " & errNum & ")" buttons {BES_OK_BUTTON} default button BES_OK_BUTTON | ||
end try |