Help, applescript to open/close an app

I've run into a problem on creating an applescript that will open or close a specific app if it is already running, unless it was just opened. I have tried to write it two ways.
tell aplication "calculator" to activate
end tell
tell aplication "calculator" to close if aplication "calculator" is running
end tell
Obviously this gets me noo where because it just opens and then closes the calculator. So I thought maybe i'd try reversing it.
tell aplication "calculator" to close
end tell
tell aplication "calculator" to activate if aplication "calculator" is closed
end tell
Works for opening the calculator the first time, but then always open calculator back up once closed. I need help to write an applescript along the lines of:
tell aplication "calculator" to activate
end tell
tell aplication "calculator" to close if aplication "calculator" is running unless "calculator" was activated by above tell statement
end tell
Or maybe an if else statement. But i think I'm going to have to have something that can check if the app is running before it closes it.
I like assigning triggers to my F keys and just want a script I can assign to one key that will open/close my calculator. I'm open to ideas. I'm willing to bet there is an easier way to do this, but I'm new to using applescripts and could use some help.

Try something like
tell application "System Events"
  get name of every process whose name is "Calculator"
  if result is not {} then
       tell application "Calculator"
            quit
       end tell
  else
       tell application "Calculator"
            activate
        end tell
  end if
end tell
BTW when posting  a question here it is best to mark it as such. You'll get more responses if people know you are asking a question rather then just making a statement.

Similar Messages

  • AppleScript to open/close GetInfo windows for all items in and iTunes playlist

    iTunes periodically loses a good portion of my Movies artwork and the most reliable way to get it back is to simply do a Get Info on the movies who's artwork is missing... with 1000+ movies it's tedious to do this by hand so looking at way to automate this.
    pieced together this (below), but doesn't work... any help appreciated...
    tell application "iTunes"
      set theMoviesPlayList to playlist "Test Playlist"
      set theMovies to (tracks of theMoviesPlayList)
    end tell
    repeat with aMovie in theMovies
      tell application "iTunes" to reveal aMovie
      tell application "System Events"
      tell process "iTunes"
      key code 34 using command down
      click button 1 of window 1
    end tell
      end tell
    end repeat

    No problem,
    I noticed that applescript was the top window and had read on Doug's applescripts about making sure the right window was selected using this command.
    The Movie artwork problem seems to be very common and many people are searching for the answer.
    You have it now!
    Its  in my iTunes scripts folder and will get good use.
    Thanks
    Chris

  • How to open and close an App on my ipad from my mac?

    Hi,
    Just like the question in the title. I have my iPad connected to my mac mini, and I want to open/close an app from my mac mini. Is there any existing tool that I can use for this purpose? Thanks for the answer.

    The iPad can not be controlled from the Mac.

  • TS1702 i've an iphone 3.1.3. sometimes, i have problems opening all the apps i downloaded in the past 4 months. other apps would open but the recent ones will begin to boot and then close itself. once, it persisted for over a week. pls help as am frustrat

    i've an iphone 3.1.3. sometimes, i have problems opening all the apps i downloaded in the past 4 months. other apps would open but the recent ones will begin to boot and then close itself. once, it persisted for over a week. it staarted again this evening, pls help as am frustrated. NB- i checked for apps update but all my apps are up-to-date. CT

    Try the usual steps: restart, reset, restore.
    http://support.apple.com/kb/HT1430
    http://support.apple.com/kb/HT1414
    If restoring using a backup doesn't help, try restoring the iPhone to factory settings and try for a while with just the Apple-included apps, to make sure it's not an issue with a third-party app. If it still has problems, it may have a hardware problem and will need to be sent to Apple.
    Regards.

  • My iPhone opens up my app (clash of clans) it loads half way then the app crashes and closes HELP!! And yes I have updated the game :(

    My iPhone opens up my app (clash of clans) it loads half way then the app crashes and closes HELP!!

    Hello, Dirk.j.fourie2525.
    Thank you for the question.  I have had issues with third party applications myself and I will do my best to help you.  I am attaching an article below that covers most troubleshooting steps for third party applications. 
    iOS: Troubleshooting applications purchased from the App Store
    http://support.apple.com/kb/ts1702
    If you are still experiencing the issue after processing the steps in this article, you may have to contact the developer of the application to report an issue. 
    Cheers,
    Jason H. 

  • I am using 3GS, it suddenly closes most apps I open( games, tools) I tried to restart iPhone , doesn't work! Please help me out SOS!!

    I can only open apple default apps now, none of the dl apps work

    Have you tried the basics from the manual?
    Restart.
    Reset.
    Restore.
    iPhone User Guide (For iOS 4.2 and 4.3 Software)

  • Hello I have a problem with a Wifi Survey app, this app is from Access Agility, however this app was working fine, but without advise stop of working, I tried to open again, but app be close after few seconds.

    Hello I have a problem with a Wifi Survey app, this app is from Access Agility, however this app was working fine, but without advise stop of working, I tried to open again, but app be close after few seconds. Every time that I tried to open it, in diagnostic and use create some files, in special one named LatestCrash-WifiSurvey.plist, this one generate an incident identifier E73B0164-CDFA-4E9E-839E-A0C021BD17A2, but this incident identifier change every time that I tried to open, the last incident identifier is: DE600EB3-AB57-4C33-8DE8-71F6788A7441.
    After of it, I checked that the app had a new version available for downloading, I took a backup of my ipad and then upgrade this app, but is the same problem, all I want is to save the projects I had in this app, I´m afraid that if I delete this app and re-install it, probably I loss my projects.
    Thanks for your help indicating how I can save my projects and see them for example in an iphone for assurance that data is not lost.
    Something that called my attention is part of the log that shows a big CPU processing, but the strange thing is I killed all applications.
    Incident Identifier: E73B0164-CDFA-4E9E-839E-A0C021BD17A2
    CrashReporter Key:   ed0ca1405ce83d4f80cb3cce063d7248d7b76e91
    Hardware Model:      iPad2,5
    Process:         WifiSurvey [139]
    Path:            /var/mobile/Applications/1BEEE35A-85FC-4BE4-B62A-39A930CB3CE2/WifiSurvey.app/Wi fiSurvey
    Identifier:      WifiSurvey
    Version:         ??? (???)
    Code Type:       ARM (Native)
    Parent Process:  launchd [1]
    Date/Time:       2013-08-08 19:01:13.476 -0500
    OS Version:      iOS 6.1.3 (10B329)
    Report Version:  104
    Exception Type:  00000020
    Exception Codes: 0x000000008badf00d
    Highlighted Thread:  0
    Application Specific Information:
    com.accessagility.wifisurvey failed to launch in time
    Elapsed total CPU time (seconds): 20.990 (user 20.990, system 0.000), 52% CPU
    Elapsed application CPU time (seconds): 19.954, 50% CPU

    See:
    iOS: Troubleshooting applications purchased from the App Store
    Contact the developer/go to their support site if only one app.
    Restore from backup. See:
    iOS: How to back up              
    Restore to factory settings/new iPod

  • HT204266 My App Store keeps struggling to load up. Requests frequently time out and searches just don't do anything. If it does load up a search, the iPad closes down App Store, returns to home screen and, upon re-opening, the search has been deleted. Hel

    I've had my iPad (retina display) since last year. Over the last few weeks the App Store struggles to load on occasion and times out completely. When searches do rarely complete, the App Store closes down and returns my iPad to the home screen and, when I open the App Store again, it has just reset the store, forcing it to load all over again. I've tried closing all running background applications, with no difference being made. Any help would be greatly appreciated.

    1. Double-click the Home button to reveal Task Bar
    2. Hold the App Store app down for a second or two until you see the minus sign
    3. Tap the minus sign to close app
    4. Re-launch the app and test
    Note: If necessary close all apps in the Task Bar

  • The books are all in my library but when I try to open them the app glitches and closes out.

    I have an iPod 4g and I had deleted the ibooks app but downloaded it again. The books are all in my library but when I try to open them the app glitches and closes out. Before the app update (ios 7) and after the update it hadn't worked (for the past week).

    I think I have found an answer on another page! If anyone else wants to know just do this:
    Hold down the home and sleep button (if the turn off button comes up just ignore it) and when you see the apple logo release the buttons and let it wake up!
    It worked for me and seem to work for a lot of people. Hope this helps!!

  • CQ1050FR desk top DVD drive would not open, used paper clip as advised in help now won't close

     would not open, used paper clip as advised in help now won't close, error message

    OK, I decided to upgrade to Mavericks. 1st I checked to see if Parallels 8 woudl work w it. It said yes, but upgrade parallels 8 1st so I did that (& then realized I should update virus def & run Windows updates also. Don't use it very much  180 days ago it said).
    Then saw some reports of mail not working so well so decided to clean out a lot of un-needed emails on my Mac. Also ran updates to Mountain Lion.
    Then closed everything & shut down. Left it off for a few min to clear out any left over electronic garbage & rebooted. Opened App store & clicked the Mavericks free download. Almost immediated it gave me error message & suggested doing it from the Purchased section.
    Ok, I tried downloading it there. 2-3 times got same almost immediate error message.
    Then, I think it was after disconnecting external HD & printer I tried again & it was looking good w download. It was fluctuating between 40-45 min time remaining & showing almost 500 mb downloaded when I got the error message again.
    btw, I also got an error message when running Windows update. There was an unknown error code when I tried updating Service Pack 1 (which it showed I needed, although I'm thinking that is kind of strange since I've had Windows 7 on a MacBookPro since shortly after I bought the original MacBookPro in April 2010. (Spilled water on it last May & Apple store said it would need expensive repair so bought this replacement that they used my Time Machine backups to install everything on. This was right as I was getting ready to move & I haven't yet found the old one to see if maybe it would work. It should be in one of my boxes).
    So, if it is having this much trouble just getting it installed I'm kind of afraid to go ahead. Wondering why some report it works fine & a lot of others saying no.
    I very frustrated since I just want to be able to have the functionality I had to be able to sync Numbers between my iPad & my Mac.

  • Whenever i open my notes app, it shows the notepad, but no numbers or letters or anything, and then it closes. what can i do to fix this? i already tried restoring it

    Whenever i open my notes app, i get this, and then it closes. What can i do to fix this? I already tried restoring it, and it still does this. Please help

    my ipod touch has the same problem. I restored it three times, but that can't help.

  • I need help to find and open a job app that I exported, was able to fill out and sign and saved and now can't open it? What did I do wrong?

    I need help to find and open a job app that I exported, was able to fill out and sign and saved and now can't open it? What did I do wrong?

    What file format did you export it to?

  • I am facing a strange problem on new iphone 5 that I bought last week. The maps app and the places in photo gallery shows the pin and my location, however there is no information of locations. Tried to close the apps, phone restart, reset etc. Please help

    I am facing a strange problem on new iphone 5 that I bought last week. The maps app and the places in photo gallery shows the pin and my location, however there is no information of locations. Tried to close the apps, phone restart, reset etc. I am accessing it via strong wireless connection and it works fine on other devices. Please help.

    zapgrap wrote:
    there is no information of locations.
    Then no information exists.  Use the Report a Problem button within the app to report it.

  • I can't close the Numbers spreadsheet anymore, nor navigate on it. I can open and close the App Numbers though. What can I do?

    Hi! I was playing around with my iPad and was opening and closing different Apps. Suddently the file I opened in Numbers got stuck. I can't navigate on it anymore, neither can I go back to the other Numbers files.
    Could you please advise, what I can do here.
    Thanks!

    Quit Numbers completely and restart the iPad.
    Go to the home screen first by tapping the home button. Quit Numbers by double tapping the home button and the task bar will appear with all of you recent/open apps displayed at the bottom. Tap and hold down on the Numbers icon until it begins to wiggle. Tap the minus sign in the upper left corner to close the apps. Restart the iPad.
    Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    Then try Numbers again.

  • I mean that i phone take time to open apps ,contact ,etc why? i close all apps and the problem still?

    i mean that i phone take time to open apps ,contact ,etc why? i close all apps and the problem still?

    Try a reset by pressing and holding the home and power buttons for 15-20 seconds until the white Apple logo appears.

Maybe you are looking for

  • GPU replacement Program

    Even though I'm experiencing the exact symptom(please check the link below) with my macbook pro, the apple store refused to repair it because it passed few months more than the covered period. What am I supposed to do? It just doesn't make sense to m

  • Material sales report

    Hello, I have some troubles writting a sales report. The problem is that, in my case, sales are processed in another application, interfaced with SAP, so sales orders & stuff are automaticaly made, so I only see the sales in reports. I don't really k

  • Gizmo VoIP on E71/72

    Hi, I would like to know please if anyone is using their Gizmo VoIP configurations to make VoIP calls. I am using Fring, set up with my Skype. There is definately a lag in the call. Even on WiFi there is a lag. I cannot notice any difference between

  • Paragraph formats

    Hi , I have a paragragh format p5 which consists of values and headings.its like this below . P5: ,,CURRENT,,&t_income&,,&t_tax&,,&t_fed&,,&t_incded&,,ENDING,,&date&,,NET,,CASH Till the ENDING heading tab everything alligns as defined in the paragrap

  • Spry repeat list break DW insert transaction?

    Hi, Does anyone know if spry repeat lists are recognized by DW as input devices? I added a few to a form, which uses the builtin DW insert record wizard, and they don't show up with the other controls in the server behavior list and they break the tr