Reputation: 781
I searched everywhere including here for a way to close a tab. I have this code that should work:
tell application "Safari"
repeat with aWindow in windows
repeat with aTab in tabs of aWindow
if name of aTab is "Facebook" then
tell aTab to close
end if
end repeat
end repeat
end tell
I have a Facebook tab open and it doesn't work, the code seemed to work when closing whole windows though…
Thanks!
Upvotes: 0
Views: 546
Reputation: 11238
Try:
tell application "Safari" to close (every tab of every window whose name = "Facebook")
You needed to include contents in the repeat loops of your code.
tell application "Safari"
repeat with aWindow in windows
repeat with aTab in tabs of (contents of aWindow)
set aTab to contents of aTab
if name of aTab is "Facebook" then
tell aTab to close
end if
end repeat
end repeat
end tell
Upvotes: 1