cookielawinfo-checkbox-functional 11 months The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". The cookie is used to store the user consent for the cookies in the category "Analytics". Cookie Duration Description cookielawinfo-checkbox-analytics 11 months This cookie is set by GDPR Cookie Consent plugin. These cookies ensure basic functionalities and security features of the website, anonymously. Necessary cookies are absolutely essential for the website to function properly. lua file and then reference this file from your main ‘a’ file. Whenever you find a script that you want to use, simply save it as a. The great thing about Hammerspoon, is that you don’t have to write your own scripts, as there’s countless ready-made scripts available online. Disconnect from the Wi-Fi, and you should get a notification warning you about the lost connection.Press the ‘Command + h + w’ keys – this should trigger the ‘Hello from Hammerspoon’ notification.Select the ‘Hammerspoon icon from your Mac’s menu bar, and then click ‘Reload config.’.You can now put these three scripts to the test: Reference ‘a’ and ‘a’,’ by copy/pasting the following script into ‘a.’ local wifi = require('wifi').Select ‘File > Open config.’ This launches the default ‘a’ file – at last, this is the file we actually need!.We now need to reference both of these files, from a. Īt this point, we have a separate ‘a’ and ‘a’ file. Copy/paste your Wi-Fi script into this window.Select ‘File > Rename…’ and give this file the name ‘a.’.Select ‘File > Open config.’ Once again this launches the ‘a’ file.Copy/paste your ‘Hello from Hammerspoon’ script into this file.Select ‘File > Open config.’ This launches the default ‘a’ file.lua files, and then reference each script from that all-important a file. In this final section, we’re going to create our scripts as separate. We may have pasted our Wi-Fi script over our original ‘Hello from Hammerspoon’ script, but it is possible to run multiple Hammerspoon scripts side by side. Reconnect to your network, and it should trigger another notification, complete with the name of the network that you’ve just connected to. Try disconnecting from your Wi-Fi network, by selecting the ‘Wi-Fi’ icon in your Mac’s menu bar and choosing ‘Turn off Wi-Fi.’ You should see a notification warning you that the Internet is disconnected. Select the ‘Hammerspoon’ icon and choose ‘Reload config.’.Select ‘File > Save’ from your Mac’s menu bar.Hs.notify.show("Connected to Wi-Fi network","",net,"") Hs.notify.show("You lost Wi-Fi connection","","","") In this section, we’re going to create a script that’ll display a notification whenever the Wi-Fi signal is lost, and then displays another notification every time your Mac connects to a new network, complete with the name of the network that it’s just connected to.Ĭopy/paste the following into your a file: wifiwatcher = hs.(function () If you don’t have a reliable Wi-Fi network, or your Mac regularly switches between different networks, then it may help to display notifications about the current state of your Wi-Fi connection. Now we know how to issue a notification, the next step is displaying a notification in response to certain events. Your custom notification should now appear onscreen. Press the ‘Command + h + w’ keys on your keyboard.Select the ‘Hammerspoon’ icon from your Mac’s menu bar and then click ‘Reload Config.’.Select ‘File > Save’ from the menu bar.Let’s start with something simple that you can test straight away, by creating a keyboard shortcut that triggers a notification.Ĭopy/paste the following into the a window: hs.hotkey.bind(, "W", function() This is where we’ll be creating our first script.Īutomate Windows Tasks with Autohotkey (Series) Your first Hammerspoon script: Displaying a notification Select ‘File > Open Config’ from the Hammerspoon menu bar. At this point, you should see Hamerspoon’s Lua console.Find the ‘Hammerspoon’ app, and give its accompanying checkbox a click.Click the little padlock in the bottom-left corner, and enter your admin password.Make sure the ‘Privacy’ tab is selected.When prompted, click ‘Open System Preferences.’ This should launch macOS’ regular ‘Security & Privacy’ window.You can select and deselect the various options, depending on your preferences, but you must enable accessibility in order to use Hammerspoon properly, so give the ‘Enable Accessibility’ button a click. The first time you launch Hammerspoon, it’ll present you with a preference pane.Once the file has finished downloading, unzip it and launch the resulting app.Make sure you download the Hammerspoon zip file, rather than the source code! Head over to its GitHub page and download the latest stable release. Let’s start by getting Hammerspoon setup:
0 Comments
Leave a Reply. |