I'm pretty new to AppleScript and wanted to make a simple script for Safari. In fact, I want to activate the last active tab after closing the current tab. This is where I'm stuck

tell application "Safari"
    close current tab of front window
    set current tab #(some code to get last active tab) 
end tell
  • I don't believe this is possible. – CJK Feb 15 at 21:35
  • @CJK why not ? there's cmd+shift+T, there's restore last active session in history menu and one can click on 10th item in history menu to get the required tab too! – ankii Feb 16 at 9:13
  • @ankii Nice ideas, but none of those will work. Restroing the last session doesn't help in any way - we're after the previously viewed tab. The history menu tells you what URLs were visited previously; it doesn't tell you which tab it was in, or when the tab was last viewed. History items from the present tab would continue to populate the list, so you'd never have an order that's associated with a tab. What's cmd-shift+T ? But if you're certain it can be done, you should give it a try and if you succeed, I will be the first to upvote you. – CJK Feb 16 at 18:01

Answer: this is not possible since the list of active previous tabs isn’t stored in a way AppleScript can know how to go back and undo a window close operation.

|improve this answer|||||

You must log in to answer this question.

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