Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Changing Safari tab order via Applescript

Hi,


I would like to move the current tab in a Safari window all the way to the left via Applescript, to accomplish the same result as can be done by dragging the tab to that position. I tried saying


set index of current tab to 1

, but that resulted in an error. Any advice would be appreciated.


Thanks,


Ken

12 G4 PowerBook, Mac OS X (10.5.8), 1.125 Gb RAM

Posted on Oct 28, 2011 8:21 AM

Reply
9 replies

Oct 28, 2011 1:06 PM in response to Kenneth Hjulstrom

Things like


tell application "Safari"

tell front window

move last tab to before first tab

end tell

end tell


or else


tell application "Safari"

tell front window

move tab 1 to after last tab

end tell

end tell

use to work. But just tried it in 5.1.1 and the window closes with no error messages anywhere. So not sure when thsi stopped working or if there is another way in 5.1 to accomplish this.


BTW the reason you get the error is that the tab index is read only.

Oct 31, 2011 7:02 AM in response to X423424X

Hi X423424X,


Your suggestion seems to give focus to the specified tab, as if the script language were saying "make tab 1 be the current tab". I'm looking for code that will actually change the order that the tabs are shown in the browser window, not a focus change, though your code suggestion might be useful as part of the solution.


Thanks,


Ken

Oct 31, 2011 7:18 AM in response to Frank Caggiano

Hi Frank,


It looks to me like your code is correct, but i can also confirm that when I try to run it on Safari 5.1.1, the window closed with no error message. I found essentially your exact code here:


http://books.google.com/books?id=ssaTrBGoO50C&pg=PA339&lpg=PA339&dq=applescript+ %22move+tab%22&source=bl&ots=_Lhd5IT8TB&sig=JRo_TX5XR19pRoEi1J9MfG354E0&hl=en&ei =2ayuTqvHLa690QGjrq2RDw&sa=X&oi=book_result&ct=result&resnum=6&ved=0CFEQ6AEwBQ#v =onepage&q&f=false


but that code just closed the Safari window as well. If nobody comes up with working code to do this, I'll submit it to Apple as a possible bug.


Thanks,


Ken

Oct 31, 2011 10:41 AM in response to Kenneth Hjulstrom

Kenneth Hjulstrom wrote:


Hi X423424X,


Your suggestion seems to give focus to the specified tab, as if the script language were saying "make tab 1 be the current tab".


You're original post said,

I would like to move the current tab in a Safari window all the way to the left via Applescript, to accomplish the same result as can be done by dragging the tab to that position.


I interpreted that as if you physically grab the current tab, which has the focus by definition, and drag it to the far left, where it would still have the focus. You said nothing about changing focus in that post. You wanted to know what was wrong with your applescript line so that's what I specifically replied to.

Oct 31, 2011 8:29 PM in response to X423424X

Hi X423424X,


Your original interpretation of my question was exactly correct. However, when I implemented your Applescript statement, it did not move the tab to the left as was what I had requested. When I ran your Applescript statement, it had the effect of switching the focus to to tab 1, which is the the tab farthest to the left. I tried this with a Safari window that had three tabs, and with the rightmost tab having focus. After running your Applescript statement, none of the tabs changed position, but tab 1 had the focus after running your statement. Since you know exactly what my original question meant when you posted this solution, obviously I'm doing something wrong. Please explain how you got this statement:


tell front window of application "Safari" to set current tab to tab 1


to move the tab with focus to the far left.


Thank you,


Ken

Nov 11, 2014 3:11 PM in response to Kenneth Hjulstrom

Hi,


A bit more than three years after I originally posted this question, I have an answer. The following script creates a new Safari tab, which by default, is positioned at the far right of the tab list, then moves it to the beginning (far left) of the tab list, sets focus to the new tab, and then populates it:


++++++++++++++++++++++++++++++++++++++++++++


tell application "Safari"

tell window 1

set current tab to (make new tab)


move tab (get index of last tab) to beginning of tabs

set current tab to tab 1


set URL of front document to "http://www.apple.com"

end tell

end tell


++++++++++++++++++++++++++++++++++++++++++++


Ken

Changing Safari tab order via Applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.