Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I see your code is working. That's great. However I'm posting this to help you learn. I see a couple small issues with your code. For example in your repeat loop you tell system events to keystroke "h". There's no need to tell system events to do that in that line because you're already in a system events tell block of code, so system events already knows to do that.</p> <p>Here's how I would write your code. This doesn't require keystrokes, which is always a good thing, and is a little more efficient. It works because if the process doesn't exist then the "set theProcess to" line errors, the code then goes into the "on error" section to delay 5, then the repeat loop tries to find the process again. If the process is found then it sets its visible property which is the same as hiding it. </p> <p>It also has a timeout mechanism to prevent the script from running forever. Use this if you like. Good luck.</p> <pre><code>set processName to "WirelessUtilityCardbusPCI" set maxTime to 180 -- we only check for 3 minutes, then end set inTime to current date repeat try tell application "System Events" set theProcess to first process whose name is processName set visible of theProcess to false end tell exit repeat on error if (current date) - inTime is greater than maxTime then tell me activate display dialog "The process " &amp; processName &amp; " could not be found!" buttons {"OK"} default button 1 with icon 0 end tell exit repeat end if delay 5 end try end repeat </code></pre> <p><em><strong>EDIT</em></strong>: I have checked the above code using the TextEdit application and it works fine. To check it with your application run the following. Make sure the application is running when you run this code. If there's an error this will display it. If there's no error 2 dialogs will display showing the progress. Report what you find.</p> <pre><code>set processName to "WirelessUtilityCardbusPCI" try tell application "System Events" set theProcess to first process whose name is processName display dialog "I have found the process" set visible of theProcess to false display dialog "I just performed the \"set visible\" code" end tell on error theError number errorNumber tell me activate display dialog "There was an error: " &amp; (errorNumber as text) &amp; return &amp; return &amp; theError buttons {"OK"} default button 1 with icon stop return end tell end try </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload