Hello all,
I am using successfully the ‘open location’ command in a sandboxed app to open a URL.
Ideally I would like to close the just opened tab again, once the user has seen it, to avoid clutter in his/her browser. This script works after giving temporary apple event entitlement for com.apple.safari:
tell application "Safari"
activate
tell application "Safari" to close (every tab of every window whose URL contains "searchTerm")
end tell
BUT - I am pretty sure that AppStore Review will not approve a blanket exception for all of Safari.
I was looking into the Safari sdef file, whether there is a scripting target in Safari that I could use instead, but failed to find a suitable one.
Is there another way to achieve a closure of a specific Safari tab in a sandboxed app, without requiring the temporary exception path for Safari?
You could try this… for me it return 2 tabs that use macscripter
property searchTerm : "macscripter"
tell application "Safari"
set query to (get name of every tab of front window whose URL contains searchTerm)
end tell
We could include a new line of code with repeat loop if there is more and 1 item.
property searchTerm : "macscripter"
tell application "Safari"
set query to (get name of every tab of front window whose URL contains searchTerm)
repeat with aItem in query
close (every tab of front window whose name is equal to aItem)
end repeat
end tell
That would work, but requires the ‘tell application Safari’ call. I would need something without calling Safari as I try to use it in an sandboxed app. And - without asking for temporary exception entitlement- it will return: Safari application is not running.
And this temporary exception entitlement is not possible to get for Safari from the App Store. I am quite sure about that.
But thank you!