-- This script assumes that SwitchResX daemon is installed and that Test1 and Test2 are…
- User
-- This script assumes that SwitchResX daemon is installed and that Test1 and Test2 are valid display set names tell application "SwitchResX Daemon" -- Activate the application activate -- Get the current display set name apply display set "Test1" -- Check if it is different from Test1 if name is not equal to "Test1" then -- Apply Test1 display set apply display set "Test1" -- Display a notification display notification "Switched to Test1 display set" with title "SwitchResX" -- Set a variable to store the current time set startTime to current date -- Create a file to indicate the script is running do shell script "touch ~/script_running" -- Repeat until 5 seconds have passed repeat until (time of (current date)) - startTime > 5 -- Check if the script is run again if not (do shell script "[ -f ~/script_running ] && echo true || echo false") as boolean then -- Exit the repeat loop exit repeat end if end repeat -- Delete the file to indicate the script is finished do shell script "rm ~/script_running" -- Check if the script is run again if not (do shell script "[ -f ~/script_running ] && echo true || echo false") as boolean then -- Apply Test2 display set apply display set "Test2" -- Display a notification display notification "Switched to Test2 display set" with title "SwitchResX" end if else -- Display a notification display notification "Already using Test1 display set" with title "SwitchResX" end if end tell
- Assistant
This AppleScript assumes that the SwitchResX daemon is installed and that Test1 and Test2 are valid display set names. The script activates the SwitchResX application and applies the Test1 display set. It then checks if the current display set is different from Test1. If it is, it applies the Test1 display set, displays a notification, sets a variable to store the current time, creates a file to indicate that the script is running, and enters a repeat loop that continues until 5 seconds have passed or the script is run again. If the script is run again, it exits the repeat loop. After the repeat loop, it deletes the file to indicate that the script is finished. If the script is not run again, it applies the Test2 display set and displays a notification. If the current display set is already Test1, it simply displays a notification.
- User
the apple script returns the error "Can’t make date "Tuesday, November 28, 2023 at 10:01:31 PM" into type number." number -1700 from date "Tuesday, November 28, 2023 at 10:01:31 PM" to number
- Assistant
I apologize for the error. It seems that there is an issue with converting the current date to a number in this line:
coderepeat until (time of (current date)) - startTime > 5To fix the error, you can modify the line to convert the current date and the start time to Unix timestamps and compare the difference:
coderepeat until (current date) - startTime > 5Here's the updated script: