2

I'm trying to get my script that works to do 2 things: run in the background every 60 seconds, and disappear from the finder and the dock.

Original:

tell application "System Events"
    set process_list to the name of every process
    if "QuickLookUIService" is in process_list then
        set ThePID to unix id of process "QuickLookUIService"
        do shell script "kill -KILL " & ThePID

    end if

end tell

When I try the following code for idle, the script stops working.

on idle

    tell application "System Events"
        set process_list to the name of every process
        if "QuickLookUIService" is in process_list then
            set ThePID to unix id of process "QuickLookUIService"
            do shell script "kill -KILL " & ThePID

        end if

    end tell
return 60
end idle

And when I add this code to hide from finder, nothing happens. Ideas?

tell application "Finder"

    set visible of process "killQuickLook" to false

end tell
  • Don't. Use launchd. – JBis Dec 10 '18 at 16:30
  • 1
    @JBis, I agree with your comment however, you might want to expound a bit more on it (maybe in an answer) as Eric McClellan might not know about launchd. – user3439894 Dec 10 '18 at 16:40
  • @Eric McClellan, Are you running this AppleScript code as a script, or an application? – user3439894 Dec 10 '18 at 16:42
  • @Eric McClellan, If running as an application, then to hide the Dock Tile... have a look at ... "If you do not want to have the Dock Tile for ..." Near the bottom of my answer A: Automator “Set PDF metadata” window size? for how to hide the Dock Tile when the application is running. That said though, I'd turn off the service vs. killing it every n seconds! Hopefully JBis will post the info on that or provide a link. – user3439894 Dec 10 '18 at 16:50
  • 1
    Found this, which is the launchd implementation of your objective. Explains how to do it step-by-step, and supplies you the necessary code (XML). – CJK Dec 10 '18 at 20:29
2

I stumbled across this link that provides a step-by-step guide to implementing the solution to this problem using launchd.

For convenience, I've copied and formatted the relevant contents of the linked page below.

How to fix QuickLookUIService memory/CPU issues in High Sierra

If you're having issues with high memory (or CPU) usage on High Sierra, this is the result of a bug with the QuickLookUIService which appears to have been introduced in that version and which unfortunately has not yet been fixed. The only workaround right now is to repeatedly force quit the quicklookuiservice.

  1. Create a new file in your favourite text editor (if you use Apple's Text Edit, make sure the file is in plain text format)

  2. Paste the xml at the end of these steps into the file

  3. Rename the file to the same as what's within the <string> tags with a .plist extension (in my example, com.zerowidth.launched.killquicklook.plist)

  4. Copy the file to your library in the LaunchAgents folder (in Finder you can use Go > Go to folder > /Users/[yourusername]/Library/LaunchAgents. You may need to type an administrator password to authorize this action

  5. After your next login/restart, you should find the memory issues caused by this to be back to normal. If you ever want to remove the service, just delete the plist file

Some explanation of what this does

A launch agent is a service that helps manage applications in Mac OS. In this case, we've written our own small launch agent program that kills the quicklook service repeatedly at an interval (the killall -9 -v QuickLookUIService part). The name of the service is within the tags (you can call it what you like) and the interval is within the <integer> tags (in my case, 5600 seconds). Feel free to change the interval to whatever works best for you (if you set it higher, it will interfere less with your normal use of preview, but also allow the service to use more memory). As a final note, bear in mind that if you are previewing a document when the service restarts, the preview will fail (you can just preview again immediately).

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>com.zerowidth.launched.killquicklook</string>
        <key>ProgramArguments</key>
        <array>
            <string>sh</string>
            <string>-c</string>
            <string>killall -9 -v QuickLookUIService</string>
        </array>
        <key>StartInterval</key>
        <integer>5600</integer>
    </dict>
</plist>


Note: Expanded to answer from comment dated Dec 10 '18 at 20:29

1

Thanks @CJK for the solution I ended up using... creating a launch agent: https://discussions.apple.com/thread/8506070

Super helpful step-by-step even if you don't know anything about launch agents.

using the launch agent version of this fix keeps from taxing additional system resources. My battery life basically tripled or quadrupled now that the buggy, energy-sapping quicklookhelper gets shut down quickly.

  • 3
    You might want to expand a little bit on your answer; the system thinks it's low quality. Why and how did this solve your problem? See Your answer is in another castle: when is an answer not an answer? – Glorfindel Dec 11 '18 at 7:58
  • 1
    If I add my solution from the comments section as an official answer, would you mind selecting it to acknowledge I helped solve your issue ? – CJK Dec 11 '18 at 18:56
  • @CJK Please add and I'll accept as answer, thanks! – Eric McClellan Jan 8 at 1:16
  • Thank you. Sorry for the delay (due to unwellness). Have now done so. – CJK Jan 21 at 23:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .