avatarNikhil Vemu

Summary

The website content provides an in-depth guide on utilizing and customizing Hot Corners on macOS, including configuring actions with modifier keys and managing multiple Hot Corner profiles for enhanced productivity.

Abstract

The article titled "You’re Underutilizing ‘Hot Corners’ (Hacks Nobody Told You Before!)" delves into the macOS feature known as Hot Corners, emphasizing its potential for productivity enhancement. It explains how users can assign specific actions to the four corners of their screen, which can be triggered by swiping the pointer towards them. The article introduces the concept of using modifier keys (Shift ⇧, Control ⌃, Option ⌥, Command ⌘) to prevent accidental activation of Hot Corners. It also presents two Automator applications created by the author to simplify the configuration process and manage multiple Hot Corner profiles. The first app, "Hot Corners Configurator," facilitates easy setup of actions and modifiers, while the second, "Profiles Configurator," allows users to create, export, and apply different Hot Corner configurations. Additionally, the article provides detailed instructions on how to configure Hot Corners via Terminal commands, complete with examples and explanations of the command structure. The author advocates for the practicality of these tools, especially for users who frequently switch between different work environments or tasks, and concludes by inviting readers to explore and subscribe for more macOS tips and tricks.

Opinions

  • The author believes that Hot Corners are an underrated macOS feature that can significantly improve productivity once properly utilized.
  • There is an acknowledgment that some users are not aware of Hot Corners or do not use them to their full potential.
  • The author suggests that the default method of configuring Hot Corners through System Settings is too complex, which justifies the creation of the "Hot Corners Configurator" and "Profiles Configurator" Automator apps.
  • The use of modifier keys is presented as a solution to the problem of accidentally triggering Hot Corners, showing the author's consideration for user experience.
  • The article promotes the idea that managing multiple Hot Corner profiles is beneficial for users with varying needs throughout the day, indicating the author's understanding of diverse workflows.
  • The author's enthusiasm for macOS customization and productivity is evident, as they encourage readers to adopt these hacks and explore further Terminal tricks.
  • By providing AppleScript code for the Automator apps, the author demonstrates a commitment to sharing knowledge and empowering users to take control of their computing environment.
Screenshot by the author

You’re Underutilizing ‘Hot Corners’ (Hacks Nobody Told You Before!)

Ever configured Hot Corners via Terminal? Here’s why you should do it.

Hot Corners is such an underrated feature of macOS. Why do I say so?

  • Some people know it exists, but almost never used it.
  • Some people don’t even know it exists. (Except that they may know swiping towards the bottom-right corner would open a Quick Note, by default)

It enables you to launch one of the 10 predefined actions by swiping your pointer towards any of the four corners of your Mac’s screen.

These are the 10 predefined actions:

Screenshot by the author

(‘ ’is for No Action.)

You can configure Hot Corners to your preference in System Settings ⚙️ < Desktop & Dock 🖥️ < Hot Corners.

(Isn’t it too deep into Settings? Right. So you may wanna use this Shortcut that takes you directly to that page. It uses the URL: x-apple.systempreferences:com.apple.Desktop-Settings.extension?HotCorners)

Now, here’s the Hot Corners configuration of a user called… say James:

Screenshot by the author

So for him, swiping towards

  • top-left corner does nothing
  • bottom-left corner displays the current application’s windows
  • top-right corner opens Notification Centre
  • bottom-right corner reveals Desktop

All good, James has set these Hot Corner configurations for productivity. He’s enjoying it.

Unfortunately, he’s often triggering them unintentionally at work when his pointer hits any of the active corners.

It’s annoying for him that the configs he made for productivity are actually hindering it. He even thought of reverting back Hot Corners to blank — that’s because he didn’t know this trick:

Set “Modifier Keys” to prevent unintentional Hot Corner triggers

This is a feature in disguise — but I think if shown up, more people would actually use Hot Corners.

While configuring a Hot Corner to… say Desktop, try holding ⌘ when clicking ‘Desktop’ — and you’ll see this:

Screenshot by the author

What does this mean? It means that in order to trigger Desktop, you’ll need to hold ⌘ and then swipe pointer towards that corner (normal swipe wouldn’t work).

This can prevent most unintentional triggers as there’s very low chance you’d hold ⌘ and swipe pointer towards a corner.

What are all the modifier keys you can use?

  • Shift ⇧
  • Control ⌃
  • Option ⌥
  • Command ⌘

Know what? You may wanna use combinations of two or more modifier keys too (reducing the probability of unintentional triggers to almost 0):

Screenshot by the author

Cool, right?

Now, Tricks for Pro-Users (And why they matter)

1Configuring Hot Corners via Terminal 2Steal this Automator app for easy Hot Corner configuration 3Create, Export, and Apply Hot Corner profiles 4Automator app that makes the profile-stuff easy

#1. Configuring Hot Corners via Terminal

I’m a coder — and I always prefer CLI (Command Line) tools over the ones with UI. Why? — CLI offers greater control over what I’m doing and is more CPU-efficient.

So, here’s how I configure Hot Corners using Terminal commands.

For example,

The command below sets bottom-left Hot Corner to action Mission Control with no modifier.

defaults write com.apple.dock wvous-bl-corner -int 2; 
defaults write com.apple.dock wvous-bl-modifier -int 0; 
killall Dock

But how?

Explaining each part of the command…

defaults write com.apple.dock writes the specified configuration to Dock settings (Coz Hot Corners are linked to Dock, internally).

wvous is the key in macOS to set and configure Hot Corners. Both of these are common for every Hot Corner command.

  • bl denotes bottom-left. Similarly,
  • br denotes bottom-right
  • tr denotes top-right
  • tl denotes top-left

corner means you’re configuring a corner to trigger an action.

modifier lets you set a modifier to a corner (like I said, you can use ⇧, ⌃, ⌥, ⌘ as modifiers). There’s no use of setting a modifier to a corner that has no action, obviously.

-int 2 after corner means you’re setting the corner to trigger Mission Control.

HERE ARE THE INTEGERS ASSOCIATED WITH EACH ACTION:
 0, 1: No Action
 2: Mission Control (We’ve used this, right?)
 3: Application Windows
 4: Desktop
 5: Start Screen Saver
 6: Disable Screen Saver
 7: Dashboard (Discontinued from macOS Catalina)
 10: Put Display to Sleep
 11: Launchpad
 12: Notification Centre
 13: Lock Screen
 14: Quick Note

-int <integer> after modifier lets you set a modifier to a Hot Corner action. In this case, it’s 0 — meaning no modifier.

HERE ARE THE INTEGERS ASSOCIATED WITH EACH MODIFIER AND COMBINATION: 
•  131072: Shift (⇧)
•  262144: Control (⌃)
•  524288: Option (⌥)
• 1048576: Command (⌘)
To use combinations, simply add the integers associated with the keys.
393216: Shift+Control (⇧+⌃)
•  655360: Shift+Option (⇧+⌥)
• 1179648: Shift+Command (⇧+⌘)
•  786432: Control+Option (⌃+⌥)
• 1310720: Control+Command (⌃+⌘)
• 1572864: Option+Command (⌥+⌘)
917504: Shift+Control+Option (⇧+⌃+⌥)
• 1441792: Shift+Control+Command (⇧+⌃+⌘)
• 1703936: Shift+Option+Command (⇧+⌥+⌘)
• 1835008: Control+Option+Command (⌃+⌥+⌘)
1966080: Shift+Control+Option+Command (⇧+⌃+⌥+⌘)

killall Dock refreshes Dock (and Hot Corners) with the latest changes applied.

Example commands for better understanding (Excluding ‘killall Dock’)

  • Set top-left corner to Mission Control:
defaults write com.apple.dock wvous-tl-corner -int 2; 
defaults write com.apple.dock wvous-tl-modifier -int 0
  • Set top-right corner to Desktop with modifier Command (⌘):
defaults write com.apple.dock wvous-tr-corner -int 4; 
defaults write com.apple.dock wvous-tr-modifier -int 1048576
  • Set bottom-left corner to Start Screen Saver with modifier Shift+Command (⇧+⌘):
defaults write com.apple.dock wvous-bl-corner -int 5; 
defaults write com.apple.dock wvous-bl-modifier -int 1179648

#2. Steal this Automator app for easy Hot Corners configuration

I understand your pain — Configuring Hot Corners via Terminal is way harder & complicated than doing it directly in System Settings.

That’s why I created this Automator app (Hot Corners Configurator) that makes the task 10x easier. (If the app doesn’t work, assign some random actions to your Hot Corners before you try again.)

Let’s look at James’s Hot Corners configuration once again (He’s now using modifiers):

Screenshot by the author

Now, this is what appears once he launches the Automator app:

Screenshot by the author

It displays the names of all the four corners along with their Action and Modifier info.

It also contains an additional option — ‘CLEAR ALL HOT CORNERS’ — that can clear all corners of their actions and (obviously) modifiers.

James wants to configure his empty top-left corner to open Launchpad with modifier as Control (⌃). So he selects TOP-LEFT ↖, and sees this:

“No Action” is highlighted because that’s the existing action (Screenshot by the author)

Now he selects ‘Launchpad’ and sees this:

‘No Modifier’ is highlighted because that’s the existing modifier (Screenshot by the author)

Here, he selects ‘Control, ⌃’ and clicks OK.

This new action and modifier gets configured in macOS System Settings. To confirm that, he can try out the Hot Corner, or even relaunch the app to see the changes reflected:

It’s reflecting! (Screenshot by the author)

That’s it. Now do you agree this is way handier to configure Hot Corners than via Terminal or System Settings?

Wanna see the app’s AppleScript code? Click here to scroll down to it in the Appendix.

#3. Create, Export, and Apply Hot Corner Profiles

If you’re a productivity freak, you might’ve already started dreaming of creating and using multiple profiles for Hot Corners, for example

  • Profile 1 (for Work): Bottom-left corner should take you to Desktop,
  • Profile 2 (for Home): Bottom-left corner should launch Screensaver.

To generalise – You should be able to create various profiles of Hot Corner configurations that you’ll use throughout the day. Once you apply a profile, all your existing configs should be replaced with new ones.

I’ll help you achieve this.

Let’s take Desktop as your default folder to store your profiles (Use cd desktop). Assuming you’ve already configured your Hot Corners for the profile we’re creating…

Use this command to save your config into a profile named myProfile:

defaults read com.apple.dock | grep wvous > myProfile.txt

myProfile.txt will be created on Desktop. Here’s what’s inside for me (for your reference):

    "wvous-bl-corner" = 3;
    "wvous-bl-modifier" = 1048576;
    "wvous-br-corner" = 4;
    "wvous-br-modifier" = 1179648;
    "wvous-tl-corner" = 0;
    "wvous-tl-modifier" = 0;
    "wvous-tr-corner" = 12;
    "wvous-tr-modifier" = 262144;

The file contains the Actions and Modifiers for all your four Hot Corners.

Now you may wanna use the Automator app I’ve given before to set different Hot Corner configurations for a new profile (let’s call it myNewProfile).

Store all your profiles in a safe place and apply them whenever you want to. But how to apply?

Use these commands:

defaults write com.apple.dock wvous-<corner_name>-corner -int <integer>; 
defaults write com.apple.dock wvous-<corner_name>-modifier -int <integer>; 
killall Dock

Just replace <corner_name> and <integer> with the corresponding values. You’ll need to do it once for every corner (So four times in total). And then the full profile will be applied.

I know — it’s hard again. So, here’s an

#4. Automator app that makes the Profile-stuff easy

I named it Profiles Configurator. Howzzat!

When toggled, you’re prompted to choose whether you wanna create a new profile or apply an existing one.

Screenshot by the author

If you choose ‘Create New Profile’:

You’ll be prompted to name your new profile.

Screenshot by the author

As you click OK, the profile will be saved in a Desktop folder named “Hot Corner Profiles” and will contain your current Hot Corner configurations.

If you give an empty name to your profile, you’re prompted to try again.

❗️Sadly, a bug I tried so hard to resolve, but couldn’t: If you end your profile name with a number, it saves successfully — but you’ll get an error while applying it (Ex: Profile2, Profile15). However, note that you can have numbers “between” the name (Ex: Profile2A).

If you choose ‘Apply Existing Profile’:

It shows all your existing profiles

Screenshot by the author

Select your preferred one and click OK. Now you can review it:

Screenshot by the author

Once you click Apply Profile, your Hot Corners will be configured to the profile you chose.

Things to Note

  • If you didn’t get the idea yet, you can export/import profiles to/from your friends.
  • If you choose ‘Apply Existing Profile’ when you don’t have any existing profile, you’ll be prompted to create one:
Screenshot by the author

Wanna see the app’s AppleScript code? Click here to scroll down to it in the Appendix.

Now, how do you find these Automator apps. Good? How often would you like to use them on a daily basis?

Lemme know by your responses!

Do you gaga over Terminal commands? Yes? Then you’ll enjoy reading these stories:

Finally,

If you love exploring new iOS & Mac apps (like me), consider subscribing to Setapp. You’ll get access to a curated collection of 240+ amazing apps for just $9.99 a month, which rather cost hundreds of dollars if purchased individually.

Join 460+ others to get notified whenever I publish a new story!

Appendix

AppleScript code for Hot Corners Configurator

on extractNumber(inputString)
    set AppleScript's text item delimiters to "="
    set stringItems to text items of inputString
    set numberString to item 2 of stringItems
    set AppleScript's text item delimiters to ""
    set trimmedNumberString to trimSpaces(numberString)
    return trimmedNumberString as integer
end extractNumber

on trimSpaces(inputString)
    return text 2 thru -2 of (inputString as text)
end trimSpaces

on getCorner(cornerString)
    set text item delimiters to " ["
    set resultString to item 1 of text items of cornerString
    set text item delimiters to AppleScript's text item delimiters
    return resultString
end getCorner

on getModifier(modifierString, whichPart)
    set text item delimiters to ","
    set resultString to modifierString
    if resultString contains "," then
        set resultString to item whichPart of text items of resultString
    end if
    set text item delimiters to AppleScript's text item delimiters
    return resultString
end getModifier

set actionMappings to {¬
    "No Action", 1, ¬
    "Mission Control", 2, ¬
    "Application Windows", 3, ¬
    "Desktop", 4, ¬
    "Start Screen Saver", 5, ¬
    "Disable Screen Saver", 6, ¬
    "Put Display to Sleep", 10, ¬
    "Launchpad", 11, ¬
    "Notification Centre", 12, ¬
    "Lock Screen", 13, ¬
    "Quick Note", 14 ¬
}

set modifierMappings to {¬
    "No Modifier", 0, ¬
    "Shift,⇧", 131072, ¬
    "Control,⌃", 262144, ¬
    "Option,⌥", 524288, ¬
    "Command,⌘", 1048576, ¬
    "Shift+Control,⇧+⌃", 393216, ¬
    "Shift+Option,⇧+⌥", 655360, ¬
    "Shift+Command,⇧+⌘", 1179648, ¬
    "Control+Option,⌃+⌥", 786432, ¬
    "Control+Command,⌃+⌘", 1310720, ¬
    "Option+Command,⌥+⌘", 1572864, ¬
    "Shift+Control+Option,⇧+⌃+⌥", 917504, ¬
    "Shift+Control+Command,⇧+⌃+⌘", 1441792, ¬
    "Shift+Option+Command,⇧+⌥+⌘", 1703936, ¬
    "Control+Option+Command,⌃+⌥+⌘", 1835008, ¬
    "Shift+Control+Option+Command,⇧+⌃+⌥+⌘", 1966080 ¬
}

set shellCommand to "defaults read com.apple.dock | grep wvous"
set hotCornersInfo to do shell script shellCommand
set linesList to paragraphs of hotCornersInfo

on getActionString(actionValue, actionMappings)
    repeat with i from 1 to length of actionMappings by 2
        if item (i + 1) of actionMappings is actionValue then
            return item i of actionMappings
        end if
    end repeat
    if actionValue is 0 then
        return "No Action"
    end if
end getActionString

on getModifierString(modifierValue, modifierMappings)
    repeat with i from 1 to length of modifierMappings by 2
        if item (i + 1) of modifierMappings is modifierValue then
            return item i of modifierMappings
        end if
    end repeat
    return "No Modifier"
end getModifierString

repeat with lineNext in linesList
    if lineNext contains "bl-corner" then
        set blCorner to getActionString(extractNumber(lineNext), actionMappings)
    else if lineNext contains "bl-modifier" then
        set blModifier to getModifierString(extractNumber(lineNext), modifierMappings)
    else if lineNext contains "br-corner" then
        set brCorner to getActionString(extractNumber(lineNext), actionMappings)
    else if lineNext contains "br-modifier" then
        set brModifier to getModifierString(extractNumber(lineNext), modifierMappings)
    else if lineNext contains "tl-corner" then
        set tlCorner to getActionString(extractNumber(lineNext), actionMappings)
    else if lineNext contains "tl-modifier" then
        set tlModifier to getModifierString(extractNumber(lineNext), modifierMappings)
    else if lineNext contains "tr-corner" then
        set trCorner to getActionString(extractNumber(lineNext), actionMappings)
    else if lineNext contains "tr-modifier" then
        set trModifier to getModifierString(extractNumber(lineNext), modifierMappings)
    end if
end repeat

set cornerOptions to {"TOP-LEFT ↖            [ACTION: " & tlCorner & ", MODIFIER: " & getModifier(tlModifier, 2) & "]", ¬
    "TOP-RIGHT ↗          [ACTION: " & trCorner & ", MODIFIER: " & getModifier(trModifier, 2) & "]", ¬
    "BOTTOM-LEFT ↙    [ACTION: " & blCorner & ", MODIFIER: " & getModifier(blModifier, 2) & "]", ¬
    "BOTTOM-RIGHT ↘ [ACTION: " & brCorner & ", MODIFIER: " & getModifier(brModifier, 2) & "]", ¬
    "CLEAR ALL HOT CORNERS"}

set selectedCorner to choose from list cornerOptions with prompt "Select a corner:" without multiple selections allowed and empty selection allowed

if selectedCorner is not false then
    set selectedCorner to item 1 of selectedCorner as text
    if selectedCorner is "CLEAR ALL HOT CORNERS" then
        set corners to {"tl", "tr", "bl", "br"}
        repeat with currentCorner in corners
            do shell script "defaults write com.apple.dock wvous-" & currentCorner & "-corner -int 0"
            do shell script "defaults write com.apple.dock wvous-" & currentCorner & "-modifier -int 0"
        end repeat

        do shell script "killall Dock"

    else
        set selectedCornerAbbreviation to ""
        if selectedCorner contains "TOP-LEFT ↖" then
            set selectedCornerAbbreviation to "tl"
        else if selectedCorner contains "TOP-RIGHT ↗" then
            set selectedCornerAbbreviation to "tr"
        else if selectedCorner contains "BOTTOM-LEFT ↙" then
            set selectedCornerAbbreviation to "bl"
        else if selectedCorner contains "BOTTOM-RIGHT ↘" then
            set selectedCornerAbbreviation to "br"
        end if

        set cornerActions to {"No Action", ¬
            "Mission Control", ¬
            "Application Windows", ¬
            "Desktop", ¬
            "Start Screen Saver", ¬
            "Disable Screen Saver", ¬
            "Put Display to Sleep", ¬
            "Launchpad", ¬
            "Notification Centre", ¬
            "Lock Screen", ¬
            "Quick Note"}

        set chosenAction to choose from list cornerActions with prompt "Action for " & getCorner(selectedCorner) default items {"No Action"} without multiple selections allowed and empty selection allowed

        if chosenAction is not false then
            if (count of chosenAction) > 0 then
                set selectedActionText to item 1 of chosenAction
                if selectedActionText is not "No Action" then
                    set selectedActionValue to 0
                    repeat with i from 1 to length of actionMappings by 2
                        if item i of actionMappings is selectedActionText then
                            set selectedActionValue to item (i + 1) of actionMappings
                            exit repeat
                        end if
                    end repeat

                    if selectedActionValue is not 0 then
                        set modifierOptions to {}
                        repeat with i from 1 to length of modifierMappings by 2
                            set end of modifierOptions to item i of modifierMappings
                        end repeat

                        set chosenModifier to choose from list modifierOptions with prompt "Modifier for " & getCorner(selectedCorner) default items {"No Modifier"} without multiple selections allowed and empty selection allowed

                        if chosenModifier is not false then
                            if (count of chosenModifier) > 0 then
                                set selectedModifierText to item 1 of chosenModifier
                                set selectedModifierValue to 0

                                repeat with i from 1 to length of modifierMappings by 2
                                    if item i of modifierMappings is selectedModifierText then
                                        set selectedModifierValue to item (i + 1) of modifierMappings
                                        exit repeat
                                    end if
                                end repeat

                                set actionCommand to "defaults write com.apple.dock wvous-" & selectedCornerAbbreviation & "-corner -int " & selectedActionValue
                                set modifierCommand to "defaults write com.apple.dock wvous-" & selectedCornerAbbreviation & "-modifier -int " & selectedModifierValue

                                do shell script actionCommand
                                do shell script modifierCommand
                                do shell script "killall Dock"
                            else
                                set actionCommand to "defaults write com.apple.dock wvous-" & selectedCornerAbbreviation & "-corner -int " & selectedActionValue
                                set modifierCommand to "defaults write com.apple.dock wvous-" & selectedCornerAbbreviation & "-modifier -int 0"

                                do shell script actionCommand
                                do shell script modifierCommand
                                do shell script "killall Dock"
                            end if
                        end if
                    end if
                else
                    set actionCommand to "defaults write com.apple.dock wvous-" & selectedCornerAbbreviation & "-corner -int 0"
                    set modifierCommand to "defaults write com.apple.dock wvous-" & selectedCornerAbbreviation & "-modifier -int 0"

                    do shell script actionCommand
                    do shell script modifierCommand
                    do shell script "killall Dock"
                end if
            end if
        end if
    end if
end if

AppleScript code for Profiles Configurator

on extractNumber(inputString)
    set AppleScript's text item delimiters to "="
    set stringItems to text items of inputString
    set numberString to item 2 of stringItems
    set AppleScript's text item delimiters to ""
    set trimmedNumberString to trimSpaces(numberString)
    return trimmedNumberString as integer
end extractNumber

on getModifier(modifierString, whichPart)
    set text item delimiters to ","
    set resultString to modifierString
    if resultString contains "," then
        set resultString to item whichPart of text items of resultString
    end if
    set text item delimiters to AppleScript's text item delimiters
    return resultString
end getModifier

on getModifierString(modifierValue, modifierMappings)
    repeat with i from 1 to length of modifierMappings by 2
        if item (i + 1) of modifierMappings is modifierValue then
            return item i of modifierMappings
        end if
    end repeat
    return "No Modifier"
end getModifierString

on trimSpaces(inputString)
    return text 2 thru -2 of (inputString as text)
end trimSpaces

on getActionString(actionValue, actionMappings)
    repeat with i from 1 to length of actionMappings by 2
        if item (i + 1) of actionMappings is actionValue then
            return item i of actionMappings
        end if
    end repeat
    if actionValue is 0 then
        return "No Action"
    end if
end getActionString

set actionMappings to {¬
    "No Action", 1, ¬
    "Mission Control", 2, ¬
    "Application Windows", 3, ¬
    "Desktop", 4, ¬
    "Start Screen Saver", 5, ¬
    "Disable Screen Saver", 6, ¬
    "Put Display to Sleep", 10, ¬
    "Launchpad", 11, ¬
    "Notification Centre", 12, ¬
    "Lock Screen", 13, ¬
    "Quick Note", 14 ¬
}

set modifierMappings to {¬
    "No Modifier", 0, ¬
    "Shift,⇧", 131072, ¬
    "Control,⌃", 262144, ¬
    "Option,⌥", 524288, ¬
    "Command,⌘", 1048576, ¬
    "Shift+Control,⇧+⌃", 393216, ¬
    "Shift+Option,⇧+⌥", 655360, ¬
    "Shift+Command,⇧+⌘", 1179648, ¬
    "Control+Option,⌃+⌥", 786432, ¬
    "Control+Command,⌃+⌘", 1310720, ¬
    "Option+Command,⌥+⌘", 1572864, ¬
    "Shift+Control+Option,⇧+⌃+⌥", 917504, ¬
    "Shift+Control+Command,⇧+⌃+⌘", 1441792, ¬
    "Shift+Option+Command,⇧+⌥+⌘", 1703936, ¬
    "Control+Option+Command,⌃+⌥+⌘", 1835008, ¬
    "Shift+Control+Option+Command,⇧+⌃+⌥+⌘", 1966080 ¬
}

on extractProfileName(fullPath)
    set fileName to last word of (do shell script "basename " & quoted form of fullPath)
    set profileName to text 1 thru ((offset of "." in fileName) - 1) of fileName
    return profileName
end extractProfileName

set userChoice to choose from list {"Create New Profile", "Apply Existing Profile"} with prompt "Choose an option:" default items {"Apply Existing Profile"} without multiple selections allowed and empty selection allowed

if userChoice is not false then
    set userChoice to item 1 of userChoice
    
    if userChoice is "Create New Profile" then
        repeat
            set newProfileName to text returned of (display dialog "Enter profile name: \n(It will have your current Hot Corner configurations)" default answer "Typing an existing profile name will replace it")

            if newProfileName is not "" then
                set desktopPath to POSIX path of (path to desktop)
                set profilesFolderPath to desktopPath & "Hot Corner Profiles/"
                do shell script "[[ -d " & quoted form of profilesFolderPath & " ]] || mkdir -p " & quoted form of profilesFolderPath
                set profileFileName to newProfileName & ".txt"
                set profileFilePath to profilesFolderPath & profileFileName

                do shell script "defaults read com.apple.dock | grep wvous > " & quoted form of profileFilePath

                display notification "Profile \"" & newProfileName & "\" created!"
                exit repeat

            else
                display dialog "Invalid profile name. Please try again."
            end if
        end repeat

    else if userChoice is "Apply Existing Profile" then
    
                set desktopPath to POSIX path of (path to desktop)
                set profilesFolderPath to desktopPath & "Hot Corner Profiles/"
                do shell script "[[ -d " & quoted form of profilesFolderPath & " ]] || mkdir -p " & quoted form of profilesFolderPath
                set profileFiles to paragraphs of (do shell script "grep -rl 'wvous-bl-corner' " & quoted form of profilesFolderPath & "/*.txt | xargs -I {} basename {} .txt")
                
                if (count of profileFiles) > 0 then
                    set chosenProfile to choose from list profileFiles with prompt "Choose an existing profile:" default items {} without multiple selections allowed and empty selection allowed
                    
                    if chosenProfile is not false then
                        set profilesFolderPath to (POSIX path of (path to desktop)) & "Hot Corner Profiles/"                    
                        set existingProfilePath to profilesFolderPath & item 1 of chosenProfile
                        set existingProfileName to extractProfileName(existingProfilePath)
                        
                        set filePath to profilesFolderPath & existingProfileName & ".txt"
                        set fileContents to read (POSIX file filePath)
                        set linesList to paragraphs of fileContents
                        
                        repeat with lineNext in linesList
                            if lineNext contains "bl-corner" then
                                set blCorner to getActionString(extractNumber(lineNext), actionMappings)
                            else if lineNext contains "bl-modifier" then
                                set blModifier to getModifierString(extractNumber(lineNext), modifierMappings)
                            else if lineNext contains "br-corner" then
                                set brCorner to getActionString(extractNumber(lineNext), actionMappings)
                            else if lineNext contains "br-modifier" then
                                set brModifier to getModifierString(extractNumber(lineNext), modifierMappings)
                            else if lineNext contains "tl-corner" then
                                set tlCorner to getActionString(extractNumber(lineNext), actionMappings)
                            else if lineNext contains "tl-modifier" then
                                set tlModifier to getModifierString(extractNumber(lineNext), modifierMappings)
                            else if lineNext contains "tr-corner" then
                                set trCorner to getActionString(extractNumber(lineNext), actionMappings)
                            else if lineNext contains "tr-modifier" then
                                set trModifier to getModifierString(extractNumber(lineNext), modifierMappings)
                            end if
                        end repeat

                        
                        set fileContent to "TOP-LEFT ↖" & return &"[ACTION: " & tlCorner & ", MODIFIER: " & getModifier(tlModifier, 2) & "]" & return & return 
                            "TOP-RIGHT ↗" & return & "[ACTION: " & trCorner & ", MODIFIER: " & getModifier(trModifier, 2) & "]" & return & return 
                            "BOTTOM-LEFT ↙" & return & "[ACTION: " & blCorner & ", MODIFIER: " & getModifier(blModifier, 2) & "]" & return & return 
                            "BOTTOM-RIGHT ↘" & return  & "[ACTION: " & brCorner & ", MODIFIER: " & getModifier(brModifier, 2) & "]"
                        
                        
                        set applyProfile to button returned of (display dialog fileContent buttons {"Apply Profile", "Cancel"} default button "Apply Profile" with title "Review profile: " & existingProfileName)
                        
                        
                        if applyProfile is "Apply Profile" then
                            do shell script "awk -F\\= '/\"wvous-bl-corner\" =| \"wvous-bl-modifier\" =| \"wvous-br-corner\" =| \"wvous-br-modifier\" =| \"wvous-tl-corner\" =| \"wvous-tl-modifier\" =| \"wvous-tr-corner\" =| \"wvous-tr-modifier\" =/ { cmd=sprintf(\"defaults write com.apple.dock %s -int %s\", $1, $2); system(cmd); }' " & quoted form of existingProfilePath & ".txt"
                            do shell script "killall Dock"
                            display notification "Profile \"" & existingProfileName & "\" applied!"
                        end if
                    end if
                else
                    set createNewProfile to button returned of (display dialog "No existing profiles found. Do you want to create a new one?" buttons {"Create New Profile", "Cancel"} default button "Create New Profile")
                    if createNewProfile is "Create New Profile" then
                            repeat
                                set newProfileName to text returned of (display dialog "Enter profile name: \n(It will have your current Hot Corner configurations)" default answer "Typing an existing profile name will replace it")
                                
                                if newProfileName is not "" then
                                    set desktopPath to POSIX path of (path to desktop)
                                    set profilesFolderPath to desktopPath & "Hot Corner Profiles/"
                                    do shell script "[[ -d " & quoted form of profilesFolderPath & " ]] || mkdir -p " & quoted form of profilesFolderPath
                                    set profileFileName to newProfileName & ".txt"
                                    set profileFilePath to profilesFolderPath & profileFileName
                                    
                                    do shell script "defaults read com.apple.dock | grep wvous > " & quoted form of profileFilePath
                                    
                                    display notification "Profile \"" & newProfileName & "\" created!"
                                    exit repeat
                                    
                                else
                                    display dialog "Invalid profile name. Please try again."
                                end if
                            end repeat
                        end if
                end if
    
    end if
end if
Technology
Apple
Mac
Macos
Productivity
Recommended from ReadMedium