AppleScript : next/Previous tab in safari

applescriptsafaritabs

I'm trying to change the focus on safari for the next tab (and the previous tab)

I wrote this which is not working :

tell application "Safari Technology Preview"
    tell window 1
        set myTabNumber to current tab
        set current tab to (myTabNumber - 1)
    end tell
end tell

How can I handle this?

Update :

Thought this would be better but nope… :

    tell application "Safari Technology Preview"
    tell window 1

        set myTab to (index of current tab)

        set goodtab to (myTab + 1)

        set current tab to tab goodtab
    end tell
end tell

Best Answer

This is what you want:

tell application "Safari"
    tell window 1
        set currentTab to (get index of current tab)
        set current tab to tab (currentTab  - 1)
    end tell
end tell

You need to be specific, otherwise you end up with type-conversion issues.