My AppleScript to change display brightness Doesn't Work - ios

Hi(first I'm not good at English.. sorry)
my device is 2019 16-inch MacBook Pro,
my os is Ventura 13.1
and my code is running on automator
my code is
set brightness to 0.7
tell application "System Settings"
reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
end tell
tell application "System Events" to tell process "System Preferences" to tell window "내장 Retina 디스플레이"
set tryUntil to (current date) + 2 -- 2 seconds
repeat
try
tell group 1 to tell tab group 1
set value of value indicator 1 of slider 1 to brightness
end tell
exit repeat
on error errorMessage
try
tell tab group 1
set value of value indicator 1 of slider 1 to brightness
end tell
exit repeat
end try
if ((current date) > tryUntil) then
error errorMessage
end if
end try
end repeat
end tell
this code from this link, very bottom
https://apple.stackexchange.com/questions/272531/dim-screen-brightness-of-mbp-using-applescript-and-while-using-a-secondary-mon
but when I click, this error image came out.. how can I fix script to change monitor brightness? Thank you.
error image when above applescript try run
perfectly running AppleScript on my computer

Related

Cypress Time out not respecting the value given on command

Since our test agents are slow some times- i am trying to add some additional time outs for some commands
I did it like using time out value on command as shown below.But its not respecting the value given
My understanding is cypress will wait for "10000" MS for getting the #Addstory element?
Can any one advice is this is the correct way please?
Thank you so much
cy.get('#addstory > .ng-scope').click({ timeout: 10000 })
In cypress.json file, increase the timeout to 10 seconds or what ever timeout you want like this: "defaultCommandTimeout": 10000 and save the file. Now close the app and open it again. Navigate to Settings > Configuration you should be able to see the new value set for defaultCommandTimeout.
I issue was i was adding time out on click not for getting the element when i changed like below -All good waiting for add story to be visible as i expected before click
cy.get('#addstory > .ng-scope',{ timeout: 10000 }).click()

Is there any way I can fold all methods in Xcode project?

Xcode provides method folding option for the current file. But is there any way to apply this to all the .m files in the project ?
p.s: I tried Xcode run scripts & Xcode plugin development, but failed to comeup with a proper solution
Here's an AppleScript for the purpose. Caveat:
System Events is required.
The script probably needs changes if you have multiple workspaces open or your workspace contains multiple projects.
You may need to have something else than an .m file selected in the project navigator.
-- Collect all Objective-C file references from the given group.
on handleGroup(theGroup, codeRefs)
tell application "Xcode"
set fileRefs to theGroup's file references
repeat with x in fileRefs
if x's file kind is equal to "sourcecode.c.objc" then
copy x to end of codeRefs
end if
end repeat
set subgroups to theGroup's groups
repeat with x in subgroups
my handleGroup(x, codeRefs)
end repeat
end tell
end handleGroup
on moveFocusToProjectNavigator()
tell application "System Events"
tell process "Xcode"
set frontmost to true
tell menu bar item "Navigate" of menu bar 1
tell menu 1
click menu item "Reveal in Project navigator"
end tell
end tell
end tell
end tell
end moveFocusToProjectNavigator
on moveFocusToNextArea()
tell application "System Events"
tell process "Xcode"
set frontmost to true
tell menu bar item "Navigate" of menu bar 1
tell menu 1
click menu item "Move Focus to Next Area"
end tell
end tell
end tell
end tell
end moveFocusToNextArea
-- Simulate pressing the up arrow.
on selectNextItem()
tell application "System Events"
tell process "Xcode"
key code 126
end tell
end tell
end selectNextItem
on fold(shouldFold)
set theCommand to "Fold Methods & Functions"
if shouldFold is equal to 0 then
set theCommand to "Unfold All"
end if
-- Fold the code by using the menu item.
tell application "System Events"
tell process "Xcode"
set frontmost to true
tell menu bar item "Editor" of menu bar 1
tell menu 1
tell menu item "Code Folding"
tell menu 1
click menu item theCommand
end tell
end tell
end tell
end tell
end tell
end tell
end fold
on run
-- Set to one to fold, zero to unfold.
set shouldFold to 1
tell application "Xcode"
set ws to every workspace document
set theWorkspace to item 1 of ws
tell theWorkspace
set pr to item 1 of projects
set codeRefs to {}
my handleGroup(pr, codeRefs)
-- Open each document and fold the code.
set thePaths to {}
repeat with x in codeRefs
copy x's full path to the end of thePaths
end repeat
end tell
-- If we only have one path, a new workspace won't be opened.
if 1 is equal to (count of thePaths) then
open item 1 of thePaths
my moveFocusToNextArea()
my fold(shouldFold)
else
open thePaths
set ws to every workspace document
set theWorkspace to item 1 of ws
my fold(shouldFold)
repeat (count of theWorkspace's file references) - 1 times
my moveFocusToProjectNavigator()
my selectNextItem()
my moveFocusToNextArea()
my fold(shouldFold)
end repeat
-- If we don't wait before closing the window, the last document
-- won't be folded.
tell application "System Events" to delay 3
tell theWorkspace to close
end if
end tell
end run
For the sake of completeness, here's an earlier attempt. It is quite slow since it needs to open one document by URL at a time.
-- Collect all Objective-C file references from the given group.
on handleGroup(theGroup, codeRefs)
tell application "Xcode"
set fileRefs to theGroup's file references
repeat with x in fileRefs
if x's file kind is equal to "sourcecode.c.objc" then
copy x to end of codeRefs
end if
end repeat
set subgroups to theGroup's groups
repeat with x in subgroups
my handleGroup(x, codeRefs)
end repeat
end tell
end handleGroup
on run
tell application "Xcode"
set ws to every workspace document
tell item 1 of ws
set pr to item 1 of projects
set codeRefs to {}
my handleGroup(pr, codeRefs)
-- Open each document and fold the code.
repeat with x in codeRefs
set thePath to x's full path
set doc to open thePath
tell doc
activate
end tell
-- Fold the code by using the menu item.
tell application "System Events"
tell process "Xcode"
set frontmost to true
tell menu bar item "Editor" of menu bar 1
tell menu 1
tell menu item "Code Folding"
tell menu 1
click menu item "Fold Methods & Functions"
end tell
end tell
end tell
end tell
end tell
end tell
end repeat
end tell
end tell
end run
Maybe much easier and better solution will be use hotkey:
When you open some .m file, just press
Cmd + Alt + Shirt + <- to fold
or
Cmd + Alt + Shirt + -> to fold
Done and dusted.
I wrote a xCode plugin which easily does the work.
plugin: https://github.com/ThilinaHewagama/HCTAutoFolding

Pre-Action run script to clear the simulator's Application Support directory

I am running automated UI tests that depend on a clean build for every run.
I'd like to add a pre-action run script that clears out anything in the Application Support directory (e.g. /Users/username/Library/Application Support/iPhone Simulator/7.1/Applications/58A5DCF7-689B-4D13-B178-A88CDE33512/Library/Application Support)
Is there an Xcode variable that makes it easy to get to that directory? Anything like $(BUILD_DIR)?
Here is what works for me:
#!/bin/bash
# `menu_click`, by Jacob Rus, September 2006
#
# Accepts a list of form: `{"Finder", "View", "Arrange By", "Date"}`
# Execute the specified menu item. In this case, assuming the Finder
# is the active application, arranging the frontmost folder by date.
osascript <<SCRIPT
on menu_click(mList)
local appName, topMenu, r
-- Validate our input
if mList's length < 3 then error "Menu list is not long enough"
-- Set these variables for clarity and brevity later on
set {appName, topMenu} to (items 1 through 2 of mList)
set r to (items 3 through (mList's length) of mList)
-- This overly-long line calls the menu_recurse function with
-- two arguments: r, and a reference to the top-level menu
tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬
(menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click
on menu_click_recurse(mList, parentObject)
local f, r
-- `f` = first item, `r` = rest of items
set f to item 1 of mList
if mList's length > 1 then set r to (items 2 through (mList's length) of mList)
-- either actually click the menu item, or recurse again
tell application "System Events"
if mList's length is 1 then
click parentObject's menu item f
else
my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
end if
end tell
end menu_click_recurse
application "iPhone Simulator" activate
menu_click({"iPhone Simulator", "iOS Simulator", "Reset Content and Settings…"})
tell application "System Events"
tell process "iPhone Simulator"
tell window 1
click button "Reset"
end tell
end tell
end tell
SCRIPT
Taken from: https://stackoverflow.com/a/14811280/1041311
Also note that it wonk work for the first time, since you need to allow Xcode to modify folders. At first run there will be dialog which will take you to System preferences where you need to give Xcode that permissions.

Applescript: Wait until "Print" dialog closes in Acrobat X

A total noob in Applescript, please bear with me…
We have a process where we use System Events to control the Print dialog in Acrobat X. This works fine; we can "click" the Print button.
Now, we have to wait until the document is printed. While the document prints, a dialog opens, with title "Print", a progress bar and a Cancel button. We can only continue when this window closes.
So far, I have not been successful with that wait; the Applescript continues and that messes up the process.
What I have currently is (note this is part of a bigger script, and variables are defined and appear to be valid.
We have Acrobat active, and the Print dialog is open:
tell application "System Events"
tell process "Acrobat"
-- now we set all the options in the Print dialog,
-- which is in the window Print
click button "OK" of window "Print
end tell
end tell
delay 5
-- this gives Acrobat time to get printing and to open that print dialog window
repeat while exists window "Print"
delay 1
end repeat
close active doc saving no
I also tried to put that code in a Timeout, but no chance.
Now, I am stuck, but I am sure it is a stupid beginner's error.
Another note: I was not able to get the name of this "Print" window using UIElementInspector.
Thanks a lot in advance for any advice.
Is your code enclosed in some tell application block that you haven't reported here?
It should work if you move the repeat loop into the tell process block:
tell application "System Events"
tell process "Acrobat"
-- now we set all the options in the Print dialog,
-- which is in the window Print
click button "OK" of window "Print"
delay 5
-- this gives Acrobat time to get printing and to open that print dialog window
repeat while exists window "Print"
delay 1
end repeat
end tell
end tell
close active doc saving no

OpenEdge ABL automatically close a yes/no message after a certon amount of time has pasted

Right now I have:
message "Hello World" view-as alert-box warning buttons yes-no update lVariable.
how can I automatically click the no after 14 seconds.
How to do this "another way":
DEFINE FRAME f-message
"This is your message"
WITH CENTERED
OVERLAY
.
DO ON ENDKEY UNDO, LEAVE:
VIEW FRAME f-message.
PAUSE 14 NO-MESSAGE.
HIDE FRAME f-message.
END.
In ChUi, you can't.
(and this is some more characters so I make the 30 char minimum for an answer.)
If you're on version 10.2b+ you might be able to use the STOP-AFTER clause on a do/for/repeat block to control this.
Not sure as I don't have that version myself to try.
BTW. Always put your version on a question as it can make a difference to the options available.

Resources