Übersicht (macOS) question: prevent image caching in widget

23 views Asked by At

I am maintaining an old CoffeeScript in Übersicht that spits out a random image from Photos. The widget refreshes every 30 minutes.

What happens is that an AppleScript executes and overwrites an image at a set location that is then used for displaying on the desktop.

My problem is that the widget seems to cache the image so that it does not load the new image upon updating.

I have tried using the update: statement to add random characters at the end of the file path via domEl but I cannot make it work. Here's the script:

command: "osascript 'RandomPhoto.widget/export_random_photo.scpt'"
refreshFrequency: '30m'
render: ->"""
"""
style: """
.leImage
  [styles here - irrelevant for this problem]
"""
render: (output) ->
  """
    <img class="leImage" src="RandomPhoto.widget/rnd.jpeg" />
  """
update: (output, domEl) ->
  s = $(domEl).find('.leImage')
  s.src = s.src + '?v=' + Math.random()

I'm not sure how Übersicht works in this matter regarding caching. If I manually force-update the entire Übersicht app it works, but that is, of course, not optimal.

1

There are 1 answers

0
max1mvs On

What did the trick for me was to write the random URL into the render section. I have no clue as to why the update didn't work:

# Render the output.
render: (output) ->
"<img class='leImage' src='RandomPhoto.widget/rnd.jpeg" + "?v=" + Math.random() + "' />"