I want to unlock mac programmatically. Currently i am using Apple script for this propose. And it is working all fine but The issue is it is time consuming process. It take around 4-5 seconds to execute the script. Here is the script i am execution using NSAppleScript. Please suggest me how can i make it work fast. or Any other fastest possible way. Thanks
tell me to activate\n
tell application \"System Events\" to keystroke \"PASSWORD\"\n
tell application \"System Events\" to keystroke return\n
tell application \"System Events\" to keystroke return"
tell application "System Events"
tell security preferences
set require password to wake to false
end tell
end tell
tell application "System Events"
stop current screen saver
end tell
tell application "System Events"
tell security preferences
set require password to wake to true
end tell
end tell
Related
I need an applescript to open safari in full screen an to hide the toolbar on mavericks.
it sounds easy but it isnt!
i need to open safari then open google in full screen mode an then hide the toolbar.
it would be the equivilent to the below sample but instead for safari
tell application "Google Chrome"
open location "http://internet.ceo.wa.edu.au/Pages/default.aspx"
end tell
tell application "Google Chrome" to activate
tell application "System Events"
keystroke "f" using {command down, shift down}
end tell
Could be simple as this:
tell application "Safari"
activate
if (count of windows) is 0 then -- Remove "if" statement if you don't want to make a new window if there is none
make new document at front
end if
tell application "System Events" to keystroke "f" using {command down, control down}
end tell
Not sure if you can make it with no toolbar at all.
Update 4/4
not sure what you can do with it but look into this program. If it works the way you want. Add a system events to use the drop downs to select the item.
The Barbarian Group has a freeware app called "Plainview", which seems to be just a wrapper around Webkit. It works as a "Fullscreen kiosk-style presentation content viewer", similar to what Chrome presentation mode does.
Anyways, it's a free download, so no risk in trying. Scroll almost to the bottom of this page:
http://barbariangroup.com
Direct download:
http://s3.amazonaws.com/plainviewapp/plainview_1.0.178.zip
Easy way:
set MyApps to {"Google Chrome", "Skype", "Finder"}
repeat with MyApp in MyApps
tell application MyApp
activate
delay 3
tell application "System Events" to tell process MyApp
set value of attribute "AXFullScreen" of window 1 to true
end tell
end tell
end repeat
I'm using AppleScript to lock the Mac from an external device (trigger) and unlock it from this same device.
Locking works great but when unlock my Mac keyboard and pads becomes unresponsive. Weird thing is when I move mousse after locking and get the password login if I enter the password the unlock makes keyboard responsive and only then.
Is it some kind of security settings I'm not aware of? How could I solve it?
Here is the script I'm using:
Lock:
tell application "System Events"
tell security preferences
set require password to wake to true
end tell
end tell
activate application "ScreenSaverEngine"
Unlock:
tell application "System Events"
tell security preferences
set require password to wake to false
end tell
end tell
tell application "ScreenSaverEngine" to quit
Please help I'm desperate. Also if you have another method you know to lock/unlock my Mac using code I would love to try it out!
Thanks!
UPDATE: To be clear when removing the password setting code (require password) the issue doesn't appear.
Meaning removing those 3 lines:
tell security preferences
set require password to wake to true
end tell
Doesn't have this issue, this is why I think it could be some security thing I'm not aware of.
UPDATE (26 Dec 2013): I didn't find any solution and bounty finished so what I'm doing is inserting my password using ActionScript (maybe this could help others having same issue). If you do have another solution I would love to know.
Try below for locking the screen, I am using the same and no issues while locking or unlocking. Hope this helps.
try
tell application "System Events"
set the process_flag to (exists process "ScreenSaverEngine")
end tell
if the process_flag is true then
ignoring application responses
tell application "System Events" to quit
end ignoring
else
set the target_app to ((path to "dlib" from system domain as string) & "Frameworks:ScreenSaver.framework:Versions:A:Resources:ScreenSaverEngine.app") as alias
tell application (target_app as string) to launch
end if
end try
Later today I'll be able to do more testing on a Mavericks machine. In the meantime, I have a little theory -- have you tested this with other screen savers "active"? I say this because I do have a couple of screen savers that are a little buggy, and I know that at least one of them needs an update for Mavericks. Which one are you using?
[UPDATE:] I did get on Mavericks and did not see the problems you described, or at least problems of that severity. I did get a little weirdness, though, possibly having to do with timing. What if you structure your script like this? For me, it covers for errors like "connection invalid" (I admit this is a little 'dangerous'; it might be good to put an upper limit of how many times it 'try's the activate by putting a counter in there):
tell application "System Events"
tell security preferences
set require password to wake to false
end tell
end tell
set connectionValid to false
repeat until connectionValid
try
activate application "ScreenSaverEngine"
set connectionValid to true
on error e
end try
end repeat
I m working on safari plugin. I have added some Qt code in it. Now I want to open "safari->preferences" pane when user clicks on QPushButton on my Qt dialog.
If it is possible in Objective-C also, please tell me.
Finally I got it.
Here is my solution:
tell application "Safari" to activate
delay 4
tell application "System Events" to tell process "Safari"
keystroke "," using command down
tell window 1
click button "Extensions" of tool bar 1
activate "Extensions"
keystroke return
end tell
end tell
Using this AppleScript we can open Safari->Preferences programatically.
I dont know a direct api.
write an apple script and use ui scripting
to tell safari
1) to open
2) to select the menuitem preferences (maybe even send key stroke cmd+,)
some script like:
tell application "System Events"
tell process "Safari"
tell menu bar 1
tell menu bar item "Safari"
tell menu "Safari"
click menu item "Preferences..."
end tell
end tell
end tell
end tell
I'm making an application, in which I need to run a code that will tell system events to keystroke a certain phrase. Like in an AppleScript, I would do:
Tell Application "System Events" to keystroke "This is a test"
I don't know how to do this from Xcode, and I would really appreciate any help. Thank you!
You can run an AppleScript from code, e.g., using OSACompileExecute. Also see QA1026.
Alternately, you can post keyboard events using the CGEvent APIs. With recent OSes, you may be able to avoid posting each letter individually using CGEventKeyboardSetUnicodeString.
I am trying to send keystrokes to the application VisualBoyAdvance using AppleScript, but I cannot get it to work.
My code, so far, is this:
tell application "VisualBoyAdvance"
activate
tell application "System Events"
keystroke "k"
end tell
end tell
When I tell VisualBoyAdvance directly, I get this error:
error "VisualBoyAdvance got an error: Can’t get keystroke \"k\"." number -1728 from keystroke "k"
I have tried telling VisualBoyAdvance directly, and I have also tried using key code 40, but I still cannot get it to work. Strangely enough, this does work:
tell application "VisualBoyAdvance"
activate
tell application "System Events"
keystroke "d" using {command down}
end tell
end tell
But that is a keyboard shortcut that shows up in the menu bar, so I guess it would be a bit different.
How can I use AppleScript to simulate a keypress and make the application respond to it? If I cannot use AppleScript for this, what else could I use?
I think you're almost there. Here's something I used for Safari; in this example, I send key code 48 (tab).
tell application "Safari"
activate
tell application "System Events" to tell process "Safari" to key code 48
end tell
AFAICS this ought to be largely independent of AppleScript support in the target process as you're asking System Events to simulate the key press via Universal Access.
For help with key codes, see this useful application: http://manytricks.com/keycodes/
It's the developer's choice to make an application fully Applescript aware. Menu items are Applescriptable from the Finder's point of view, but other UI options may or may not be. See UIElementInspector to examine that application for scriptable elements.
I can't garuntee anything as I don't have this app but here is some things to try
tell application "VisualBoyAdvance"
activate
tell application "System Events"
tell application process "VisualBoyAdvance"
try
keystroke "k"
on error
try
keystroke (ASCII character 75)
end try
end try
end tell
end tell
end tell