I have been trying to run a script on a recurring basis via an apple service.
Most answers I have seen have been are for 'stay-open' apps - whilst this possibly works as a solution and I have glanced information about hiding from the dock/application switcher this isn't an elegant solution for me I don't feel. Advice in the comments of this answer says that the 'on idle' call of a script only works when it is saved as a 'stay-open application', but is there an automator-native way of getting a service to execute it's script at an interval?
With the answer linked above the launchd option described is probably the best solution so really on an academic level I am just curious whether this is possible with an Automator service running some applescript
If it helps frame the context of the question any better here is the code I want to run:
on logSomething(message) tell application "Finder" tell me to log message end tell end logSomething on getCurrentApps() tell application "System Events" set processList to get the name of every process where background only is false return processList end tell end getCurrentApps on storeAppName(thePath, applicationName) --this creates an object vehicle in which to store data script theData property appName : applicationName end script store script theData in file thePath replacing yes return theData's appName end storeAppName on readAppName(thePath) tell application "System Events" if exists file thePath then set theScript to load script file thePath return theScript's appName else return false end if end tell end readAppName on idle set dataPath to "tmp:unhide_windows_data.scpt" set storedProcess to readAppName(dataPath) tell application "System Events" set currentProcess to first process where it is frontmost -- my logSomething("currentProcess windows: " & (the name of windows of the currentProcess)) if currentProcess's name is equal to storedProcess then --report that the stored and observed process name are the same display dialog "They are the same" my logSomething("Is the current process visible? " & (visible of currentProcess as text)) else --report that the stored and observed process name are not the same display dialog "They are not the same, storedProcess: " & storedProcess & ", currentProcess: " & currentProcess's name my storeAppName(dataPath, currentProcess's name) set visible of currentProcess to true end if end tell readAppName(dataPath) return 5 end idle