Applescript: how to script keystrokes?

Hello, I am trying to use Applescript to 'clear browsing data' in Chrome.  I'm trying to emulate clicking command-shift-delete to bring up the frame showing the browser clearing options, and then tab-return to click the button. When manually using these keystrokes it works perfetly.  However, I copied some script from this forum and modified it as follows, and can't get it to work:
tell application "Google Chrome" to activate
tell application "System Events"
   key code 13 using {command down, option down}
   delay 0.55
   key code 45 using {command down}
   delay 0.55
end tell
tell application "Google Chrome"
   tell first window
       set bounds to {0, 0, 1280, 800}
   end tell
end tell
tell application "System Events"
   key code 51 using {command down, shift down}
   key code 48
   key code 76
end tell
I also tried substituting "keystroke tab" and "keystroke return" for the last 2 key codes above.  Any help with this will be greatly appreciated.

I don't really know what the first part of your script is intended to do, but focusing on the issue you describe, I think you just need a delay to allow the frame to be displayed:
tell application "Google Chrome" to activate
tell application "System Events"
  key code 51 using {command down, shift down}
  delay 1
  key code 48
  key code 76
end tell

Similar Messages

  • How to tell if item is a folder or volume with applescript or shell script?

    I am working on a service in Automator that will eject the selected drive when it is finished. Unfortunately automator can only tell the difference between files and folders for the service menu.
    Im wondering if if i can use an applescript or shell script that would check if the selected folder is a volume or folder and quit the action if its a folder. I figure the best way to do this is have it determine if the items path is in /Volumes/, but i am completely new to the process and have no idea how to do this.
    My automator workflow looks like:
    Ask for Confirmation
    Get Selected Finder Items
    Shell Script
    I have the path of the folder selected being passed into the shell script, but after its in there i dont know how to determine if its a volume or not.
    Thanks!

    K T,
    I completely missed that section of the forums, sorry
    Neil,
    I had that kind of script set up but it was like this:
    on run {input, parameters}
    tell application "Finder"
    kind of item parameters
    end tell
    end run
    And i just figured out that i had to change the first line to "on run {parameters}" and now it works great.
    Thanks for the help, it got me going in the right direction

  • Powerpoint make movie - how to script this?

    I want to convert a Powerpoint File (ppt) to a QT movie. Does anybody know how to script this with AppleScript?
    Thanks!

    Bernhard,
    Here is a follow-up script that works in the previous version of PowerPoint (v.X). I am not sure how much the latest version of PowerPoint has changed with regards to the location of the "Make Movie..." command or the dialog windows that are related to that command but hopefully not at all. Try it out and see whether it does what you are wanting. I assumed that you would want the movie placed in your Movies folder and that the default settings in the dialogs were okay.
    click here to open this script in your editor<pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">property delayTime : 2
    on run {}
    -- Use the "Make Movie..." command in PowerPoint to make a QuickTime movie
    tell application "System Events"
    tell process "Microsoft PowerPoint"
    set frontmost to true
    set theNameOfPresentation to title of last window
    -- Click on the Make Movie... command in the File menu
    perform action "AXPress" of menu item "Make Movie..." of menu 1 of menu bar item "File" of menu bar 1
    repeat until ((exists of sheet 1 of window theNameOfPresentation) is true)
    end repeat
    -- Move to the the Desktop
    keystroke "d" using {command down}
    delay delayTime
    -- Enter the name of the Presentation
    set value of text field 1 of sheet 1 of window theNameOfPresentation to theNameOfPresentation & ".mov"
    delay delayTime
    -- Click on the Save button
    perform action "AXPress" of button "Save" of sheet 1 of window theNameOfPresentation
    delay delayTime
    end tell
    end tell
    -- Move the newly created movie from the Desktop to the Users Movies folder
    tell application "Finder"
    delay delayTime
    try
    move file (theNameOfPresentation & ".mov") of desktop to (path to movies folder)
    on error errNum
    display dialog errNum
    end try
    end tell
    end run
    </pre>
    PowerBook 12" Mac OS X (10.4.6)

  • How to send keystrok thru program

    hi,
    can anyone tell me, how to send keystroke event to my application programatically. I have to send 'F1' key event.
    thanks in advance
    debashis roy

    Reply 10 of this thread shows you how to send a Ctrl-F1 Keystroke to a component.
    http://forum.java.sun.com/thread.jsp?forum=31&thread=224581
    To just send F1 to the component I think you just replace "KeyEvent.CTRL_MASK" with 0.

  • How to script out to connect to Active Directory specific domain controller server?

    How to script out a script that enable us to connect to the specific domain controller server, it is because I have 2 different servers version and both of them have been communicate with powershell, thus, I wanted to powershell to communicate with one
    server version. How to script this out? 

    Please see the Posting Guidlines:
    http://social.technet.microsoft.com/Forums/en-US/a0def745-4831-4de0-a040-63b63e7be7ae/posting-guidelines?forum=ITCG
    and this article on how to ask questions in a technical forum:
    http://sincealtair.blogspot.com/2010/04/how-to-ask-questions-in-technical-forum.html
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • How to script schedule in sql server agent

    Hi,
    How to script schedule in sql server 2005. When I click on script option in manage schedule, there is message ' there is no action to script'. So my question is how to create script for these schedule?
    Thanks

    As far as I can tell, there is no way to script an entire schedule using SSMS..
    Hi D.,
    this is not true - you can create, alter and delete ANY schedule with SSMS.
    msdb.dbo.sp_add_schedule: create a new schedule
    msdb.dbo.sp_update_schedule: alter an existing schedule
    msdb.dbo.sp_delete_schedule: removes a schedule
    msdb.dbo.sp_attach_schedule: set a schedule for an existing job 
    msdb.dbo.sp_detach_schedule: remove a schedule from a job
    @dba_learner
    all above stored procedures are located in msdb and fully documented.
    Scripting of elements of a job can only take effect if you do any changes to it. Otherwise the best practice is th click right on the job -> [Script job...]-> [create to new window] to get the COMLETE syntax for the creation of the job. There is one step
    for the schedule and its usage, too!
    Uwe Ricken
    MCM SQL Server 2008
    MCSE - SQL Server 2012
    MCSA - SQL Server 2012
    db Berater GmbH
    http://www-db-berater.de
    SQL Server Blog (german only)

  • How many scripts do you work on simultaneously?

    We'd love to know how many scripts do you work on at a given time?
    Is it safe to assume that you'd work on no more than 3 scripts at a time?
    --Anubhav
    Anubhav Rohatgi
    Product Manager, Adobe Story

      In my experience it depends on what type of assignments one can get.  When working a feature, you pretty much are working on one script, if working on spec, this could go as high as five or six, though you only concentrate on one at a time.
      Series television, especially complicated multi-episode story arcs can have something on the order of ten scripts in various stages of development.  Where I have not personally worked on such a series, I have heard that character groups will be assigned to a given writer, and four or five writers will contribute their scenes to the final script.  The colaborative tools of Adobe Story would lend itself well to this sort of workflow.
      I don't think I would like to see an upper limit on scripts in the program personally, though I suspect why you are asking.  The higher you can allow the better, especially if this tool is to be adopted by one hour drama writers.

  • What is shell scripting? get me notes of that... how shell script is relate

    what is shell scripting? get me notes of that... how shell scripting is related to sql or plsql?

    shell scripting is the process of creating programs which are able to execute using a shell.
    a shell is the program you use when you are logged in to a linux (or unix) system via ssh (or if you are outdated by 10 years: telnet).
    there are much shells, traditionally, unix system use the bourne shell (visible as sh most of the time), the kornshell (ksh) and c-shell (csh) extended the bourne shell functionality. nowadays there are very much shells, most linux systems use the bourne again shell (bash). the bash shell is available for most linux/unix systems, I always advise to use it on any system, so the shell functions the same on all platforms.
    if you want to know more about shell scripting, use "google". the website of google is http://www.google.com, and usage is free. use the keywords "bash shell scripting".

  • Is there an AppleScript or Automator Script that will wake a Mac from Sleep?

    Is there an AppleScript or Automator Script that will wake a Mac from Sleep?

    Frank and All,
    The following answer to your question above is complicated, but I hope it explains why my question was formed with so much frustration in it.
    I have an OpenOffice(OO) Macro that was launched with Calendar at 6pm each business night. It ran properly in all Apples operating systems until I Hit Maverick(OSX10.9). From then on, the AppleScript would run from one to 3 days, then would disappear from the Calendar entry. The Calendar alert would still run, but the "OpenFile" section of the alert would disappear. I also was running elgato EyeTV HD during the day, so I would use energy saver to put my MacBook Pro to sleep at 12 Midnight and wake it again at 9am. I picked up a used Mac Mini to do the EyeTV stuff, provide AppleTV the files in H264 format through iTunes' media share, and found it had plenty of power to do the 6pm automated stuff simultaneously as well. Because I still wanted to run the OpenOffice Macro on my MacBook Pro at 6pm, and wanted to use it for a host of other things when I was on the road, I wanted it to sleep most of the time and only wake up automatically to run the 6pm OO Macro. When I called Apple about the issue I was having with Maverick and Calendar loosing the OpenFile command as part of the Alert Message, they told me the no longer supported answering AppleScript Questions but they now would support Automator questions. I pointed out that the OpenFile would also fail after one to three days if I used a Calendar Alert to launch an Automator App. At first, I did not like Automator, but now I see why Apple is pushing us to use it. Automator adds a TIME STAMP ID to the Apps developed in Automator so the first time you launch the App after a change to it, you must reply to a dialog message saying that this is the first time you are running this version of the App. If a Scammer has replaced your app with one that can reek havoc on your computer, the replacement app will not run unless you are there to agree that you know where the modified app came from and click the OK button to continue (BRILLIANT, Enhanced Security idea on Apples part). I also noticed that after Mountain Lion, the Applescript delay timing was all screwed up as well. Well I tried to use LaunchD Task Scheduler to circumvent the Calendar Problem and that worked until I upgraded to Yosemite Last week. Then LaunchD no longer worked and I am only into a few days of using The Calendar Launched Automator App to see if it will continue to run.
    But I think I solved the dilemma I was having with opening an Automator App in a Sleeping Mac. I Googled up the following question, "AppleScript to wake up computer".  I went thru several complex responses until I found this on that is INCREDIBLE EASEY! What came back was a brettterpstra.com  response from Feb 20th,2014. What it said, in a Quick Tip: caffeinated your Terminal Article,  if you wanted to wake a Mac from sleep, use the Terminal command named "Caffeine -u -t 1". I placed it in an Automator Most Used Action called "Run Shell Script -- Caffeine -u -t 1" and it worked!  Now, I can put my Mac to Sleep but at 6pm, the Automator App will launch, run the "Caffeine -u- -t 1" command and proceed to work as if I had awakened the Mac From Sleep mode by pressing a keyboard key and had run the Automator Script with a double click.
    Sorry for the long, drawn-out reply, but maybe this will help others.

  • AppleScript: How to let AppleScript use the same environment as Bash shell does?

    Howdy!
    I can run AppleScript from Bash shell.
    I can also run Bash shell from AppleScript.
    So my question is when I run a Bash shell script from AppleScript, I am hit with a path problem.
    Suppose my AppleScript is under ~user/a.scpt. I want my AppleScript to know its current path (i.e. ~user/a.scpt).
    So a quick snippet test in my AppleScript shows that AppleScript always begins from the root directory:
    do shell script "pwd"
    So let's do a workaround AppleScript like this:
    tell application "Finder" to set currentDir to (target of front Finder window) as text
    do shell script "cd " & (quoted form of POSIX path of currentDir) & "; pwd"
    This works. However, this approach poses a potential danger.
    Suppose when I run this AppleScript for a bash script, I inadvertently clicked other Finder Window. That would result in execution of bash script in that newly clicked Finder Window, resulting in a big mess.
    Is there a better way to let the AppleScript to know its current path?

    The following is what your Applescript environment looks like, so plan accordingly.  If you want your Applescripts to be portable to other user environments, you should NOT depend on your environment, but rather embed all the environment knowledge you need into your script.
    Applescript "do shell script" environment
    pwd:
    /bin/ls -dlaeO@ .
    drwxr-xr-x  36 root  wheel  - 1292 Feb 28 09:58 .
        /usr/bin/id -a
    uid=501(raharris)
    gid=20(staff)
    groups=20(staff),
    402(com.apple.sharepoint.group.1),
    12(everyone),
    61(localaccounts),
    79(_appserverusr),
    80(admin),
    81(_appserveradm),
    98(_lpadmin),
    403(com.apple.sharepoint.group.2),
    33(_appstore),
    100(_lpoperator),
    204(_developer),
    398(com.apple.access_screensharing),
    399(com.apple.access_ssh)
    $#
    0
    $0
    /path/to/your/shell/script
    printenv:      
    SHELL=/bin/bash
    TMPDIR=/var/folders/4t/t1djbq6j5pj951x44l9hwxtc0000gn/T/
    Apple_PubSub_Socket_Render=/tmp/launch-mSKKJo/Render
    USER=<username_running_the_Applescript>
    SSH_AUTH_SOCK=/tmp/launch-7D4zpF/Listeners
    __CF_USER_TEXT_ENCODING=0x1F5:0:0
    PATH=/usr/bin:/bin:/usr/sbin:/sbin
    __CHECKFIX1436934=1
    PWD=/
    HOME=/Users/<home_dir_of_running_user>
    SHLVL=2
    LOGNAME=<username_running_the_Applescript>
    DISPLAY=/tmp/launch-qKucki/org.macosforge.xquartz:0
    _=/usr/bin/printenv
    Message was edited by: BobHarris

  • How to Script the "Upgrade Database" button in Configuration manager?

    Hi
    We want to automate the cloning process of the test env. to the dev. env. only problem is that the DBA is testing newer CU on dev, which means that we have to push the "Upgrade Database" button in configuration manager each time... any good solution
    to this?
    in short:
    How to Script the "Upgrade Database" button in Configuration manager?
    thanks!
    MM

    MM, is this still an issue?
    Thanks!
    Ed Price, Azure & Power BI Customer Program Manager (Blog,
    Small Basic,
    Wiki Ninjas,
    Wiki)
    Answer an interesting question?
    Create a wiki article about it!

  • Applescript: How to run a script once upon logon for multiple users

    I'm deploying a NetRestore image to about 150 Macs which will be using Active Directory and I've designed a custom default user for each new user. However, our system requires a specialized certificate that has to be installed on the local login.keychain for each user otherwise network connectivity is impacted.
    I've tried to use the security command through Terminal to install the certificate, but no matter what combination of commands, I cannot seem to get that to work properly even with an already-created user. While it will often say it's installed, the cert will not actually show up in the login keychain in Keychain Access. And the network connectivity is still impacted.
    So instead, I created a brief AppleScript that just gives the user brief instructions to click "Add" on the prompt for which Keychain to add the cert and then "Always Trust" for the "This cert is not verified" prompt. Then it launches Keychain Access. Originally, I was going to have it actually click the buttons for the user, but I realized trying to get the whole Accessibility apps and assitive devices to work on every new user would be a nightmare.
    I created the script on another 10.9 Mac using Automator to make it an actual application. I've used the instructions in OS X: Using AppleScript with Accessibility and Security features in Mavericks to sign it and I'm using root to move it from its network location into the Applications folder. I've adjusted the permissions to allow all Admin users to r/w (along with everyone else). To the root user, it shows as a usable application, but every other user on the Mac sees it as damaged/incomplete.
    What I want to do is add it to the default Login Items, so I can run the final AppleScript command to simply remove the login items listing. That way I don't need to worry about it running again, but it's still available for the next user to sign onto the deployed Mac.
    I know it's a little convoluted, but this is the final piece to the NetRestore deployment I've been working on for months. Any suggestions on how to make this work (or even a completely different solution) would be greatly appreciated.
    Here was the original shell script in case you're curious.
    #!/bin/bash
    ## Prompt for current user admin for use in Certificate Install
    while :; do # Loop until valid input is entered or Cancel is pressed.
        localpass=$(osascript -e 'Tell application "System Events" to display dialog "Enter your password for Lync Setup:" default answer "" with hidden answer' -e 'text returned of result' 2>/dev/null)
        if (( $? )); then exit 1; fi  # Abort, if user pressed Cancel.
        localpass=$(echo -n "$localpass" | sed 's/^ *//' | sed 's/ *$//')  # Trim leading and trailing whitespace.
        if [[ -z "$localpass" ]]; then
            # The user left the password field blank.
            osascript -e 'Tell application "System Events" to display alert "You must enter the local user password; please try again." as warning' >/dev/null
            # Continue loop to prompt again.
        else
            # Valid input: exit loop and continue.
            break
        fi
    done
    echo $localpass | sudo security import /'StartupFiles'/bn-virtual.crt ~/Library/Keychain/login.keychain
    osascript -e 'tell Application "System Events" to delete every login item whose name is "LyncCert"
    And this is the AppleScript itself. (I used the \ to make it easier to read. The first line is actually one complete command)
    display dialog "Click OK to start installing Mac Network Certificate." & return & return & \
    "In the following prompts, click the 'Add' then 'Always Trust'." & return & return & \
    After you have clicked 'Always Trust', quit Keychain Access." default button 1 with title \
    "Mac Network Certificate Install"
    activate application "Keychain Access"
    tell application "Finder" to open POSIX file "/StartupFiles/bn-virtualcar.crt"
    tell application "System Events" to delete login item "Lync-AppleScript"
    end
    Thank you for your help!

    I have run into this same issue. Are you trying to run the script one time as a new  user logs in or everytime a user logs in?

  • AppleScript: How to pass control to dialog when it is opened using do script

    I am running the following AppleScript:
    tell application "Adobe Acrobat Pro" to activate
    tell application "Adobe Acrobat Pro"
              do script "app.execMenuItem(\"GeneralPrefs\");"
      delay 2
              tell application "System Events"
                        tell process "Acrobat"
                                  click button "OK" of window "Preferences"
                        end tell
              end tell
    end tell
    This properly opens the Preferences dialog/window. This part does work. However, then, the script gets stuck and waits until the window closes for continuing. And then, it is no longer possible to click the OK button…
    Am I missing something, and how can I get controls back to the AppleScript when the dialog window has opened?
    Any advice is highly appreciated.
    Max Wyss.

    I am running the following AppleScript:
    tell application "Adobe Acrobat Pro" to activate
    tell application "Adobe Acrobat Pro"
              do script "app.execMenuItem(\"GeneralPrefs\");"
      delay 2
              tell application "System Events"
                        tell process "Acrobat"
                                  click button "OK" of window "Preferences"
                        end tell
              end tell
    end tell
    This properly opens the Preferences dialog/window. This part does work. However, then, the script gets stuck and waits until the window closes for continuing. And then, it is no longer possible to click the OK button…
    Am I missing something, and how can I get controls back to the AppleScript when the dialog window has opened?
    Any advice is highly appreciated.
    Max Wyss.

  • How to make Cocoa-Applescript do the script?

    I took my script from the original Applescript Editor and pasted it into Xcode, changing all the terms incompatible with Cocoa. At first I pasted it in between the already there code in the "Applescript.deligate" file. I built it, launched it, but... It did nothing. Then I tried deleting all the code in it and pasting only my own, again nothing. Is there a "Do Script" command or something? How do I get the application to do the script? (Mostly UI scripting)

    AppleScript in Xcode is a little bit different in that there isn't an implied run handler, so your code needs to be in a handler and won't get run unless you explicitly call it.  One way to start your script would be by calling it from one of the delegate handler/methods such as applicationDidFinishLaunching, or by using an action handler/method connected to a button or other object in your application's user interface.

  • How to script an auto clicking program in AppleScript with multiple mouse locations

    I have no experience in scripting but I want to make an auto clicking program where it click in 3 different locations on the screen in a sequence. Is this possible with to do with apple scripts? I am using a MacBook Pro (15-inch, Mid 2012) OSX Yosemite.

    This is a python script wrapped in an Applescript.
    See the 3 mouseclick(x, y); commands near the end that clicks 3 positions on the menu bar.
    do shell script "
    python <<-END
    import sys
    import time
    from Quartz.CoreGraphics import *
    def mouseEvent(type, posx, posy):
            theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
            CGEventPost(kCGHIDEventTap, theEvent)
    def mousemove(posx,posy):
            mouseEvent(kCGEventMouseMoved, posx,posy);
    def mouseclick(posx,posy):
            mouseEvent(kCGEventLeftMouseDown, posx,posy);
            mouseEvent(kCGEventLeftMouseUp, posx,posy);
    time.sleep(2);
    ourEvent = CGEventCreate(None);
    currentpos=CGEventGetLocation(ourEvent); # Save current mouse position
    mouseclick(5, 10);
    time.sleep(2);
    mouseclick(200, 10);
    time.sleep(2);
    mouseclick(300, 10);
    time.sleep(2);
    mousemove(int(currentpos.x),int(currentpos.y)); # Restore mouse position
    END

Maybe you are looking for

  • Home movies from DVD to Mac hard drive

    I am an absolute neophyte at playing with video files. I have some VHS camcorder home movies from when my kids were little. A few months ago I asked the local photo shop to copy the videotapes onto DVDs. Now I'd like to save those videos as computer

  • Obsticles moving within WCS MAP Editor

    I have an issue whereby I import a floor plan into WCS and then open the map editor and draw over the map the wall obsticles so as to have the heat maps and RF predictions reflect the attenuation characteristics of the walls. I save the map and at a

  • Orientation of iPhotos photos in Web Gallery

    Does anyone know why it is that when I upload pictures from my camera to iPhoto, create an event and album, rotate the pictures that are not upright, and then publish the event/album to Web Gallery that the pictures that I rotated in iPhoto are no lo

  • 2 vs 2.16 Ghz

    I'm brand new to Apple and in the next week or so am going to purchase my Macbook Pro. I was wondering how significant the performance difference would be between the 2 Ghz and 2.16 Ghz processors and if it's worth the money. I'm excited to finally b

  • Oracle BI Discoverer 10.1.2.3

    Greetings All, In order to integrate BI Publisher with Discoverer here are the steps I found: 1.      Have access to or have Installed Oracle Application Server 10.1.2.2. Then download and install the one-off Discoverer Patch. Go to the Oracle MetaLi