Advertisement
Guest User

Z2 Profile switch based on window title

a guest
Feb 19th, 2025
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Step Alpha: Set up mic check and game tracking variables
  2. set windowTitles to {"Ready or Not on GeForce NOW", "Fortnite® on GeForce NOW", "S.T.A.L.K.E.R. 2: Heart of Chornobyl on GeForce NOW"}
  3. set profileNames to {"Ready Or Not", "Fortnite", "Stalker 2"}
  4. set gameCheck to false
  5. set targetWindow to ""
  6.  
  7. -- Check if yabai is running
  8. set yabaiStatus to do shell script "pgrep -x yabai > /dev/null && echo running || echo stopped"
  9. log "Yabai Status: " & yabaiStatus
  10.  
  11. if yabaiStatus is "stopped" then
  12.     log "Starting yabai service..."
  13.     do shell script "/opt/homebrew/bin/yabai --start-service"
  14.     delay 1 -- Ensure yabai has time to start
  15. end if
  16.  
  17. -- Step 4: Monitor GeForceNOW process
  18. repeat
  19.     delay 1
  20.     try
  21.         set isRunning to (do shell script "pgrep -x 'GeForceNOW' > /dev/null && echo true || echo false")
  22.         log "GeForceNOW Running: " & isRunning
  23.        
  24.         if isRunning = "false" then
  25.             set gameCheck to false
  26.             log "Game Check Reset: GeForceNOW closed."
  27.             exit repeat
  28.         end if
  29.        
  30.         -- If no game is detected, check open windows
  31.         if gameCheck is false then
  32.             log "Checking for game windows..."
  33.             set windowList to do shell script "/opt/homebrew/bin/yabai -m query --windows | /usr/bin/jq -r '.[].title'"
  34.             log "Window List: " & windowList
  35.            
  36.             set foundTitles to paragraphs of windowList
  37.            
  38.             repeat with i from 1 to count of windowTitles
  39.                 set currentWindow to item i of windowTitles
  40.                 log "Checking window: " & currentWindow
  41.                
  42.                 if currentWindow is in foundTitles then
  43.                     set targetWindow to currentWindow
  44.                     set profile to item i of profileNames
  45.                     log "Game detected: " & profile
  46.                     do shell script "osascript -e 'say \"" & profile & " detected, switching profile\"' &>/dev/null &"
  47.                     do shell script "echo 'echo -n \"" & profile & "\" | /usr/bin/nc -U /tmp/swiftpoint.x1.profileswitch' | /bin/bash"
  48.                     set gameCheck to true
  49.                     exit repeat
  50.                 end if
  51.             end repeat
  52.         end if
  53.        
  54.         -- Monitor the game window
  55.         if gameCheck is true then
  56.             set retryCount to 2 -- Number of times to check before assuming the window is closed
  57.             set isWindowOpen to "false"
  58.            
  59.             repeat with attempt from 1 to retryCount
  60.                 set isWindowOpen to (do shell script "/opt/homebrew/bin/yabai -m query --windows | grep -q '\"title\":\"" & targetWindow & "\"' && echo true || echo false")
  61.                
  62.                 -- Exit the loop early if the window is still open
  63.                 if isWindowOpen is "true" then exit repeat
  64.                
  65.                 -- Wait 1 second before retrying
  66.                 delay 1
  67.             end repeat
  68.            
  69.             -- If the window is still missing after retries, reset the profile
  70.             if isWindowOpen is "false" then
  71.                 do shell script "osascript -e 'say \"Game session ended, resetting zee two profile to Desktop.\"' &>/dev/null &"
  72.                 do shell script "echo 'echo -n \"Desktop\" | /usr/bin/nc -U /tmp/swiftpoint.x1.profileswitch' | /bin/bash"
  73.                
  74.                
  75.                 set gameCheck to false
  76.             end if
  77.         end if
  78.        
  79.        
  80.        
  81.     on error errMsg
  82.         display dialog "Error checking GeForceNOW status: " & errMsg
  83.         exit repeat
  84.     end try
  85. end repeat
  86.  
  87. -- Step 7: Reset Z2 Profile
  88. log "Resetting Z2 Profile..."
  89. do shell script "osascript -e 'say \"Default Desktop Zee two profile has been set. G G\"' &>/dev/null &"
  90. do shell script "echo 'echo -n \"Desktop\" | /usr/bin/nc -U /tmp/swiftpoint.x1.profileswitch' | /bin/bash"
  91.  
  92. -- Step 8: Stop yabai service
  93. log "Stopping yabai service..."
  94. do shell script "/opt/homebrew/bin/yabai --stop-service"
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement