Impossible de convertir «class bTab» 1 of window id 88 of application "Safari" en type real.
Here is a version which is no longer localization dependant.
------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/05/20 17:30
# dMod: 2017/05/20 17:42
# Appl: Safari
# Task: Get Tab Index and Window ID of every window as a list
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Safari, @Tab_Index, @Window_ID
------------------------------------------------------------------------------
set x to "Can't make %1 into type $2."
set theBundle to ((path to library folder from system domain) as text) & "Components:AppleScript.component:"
set cantMake_loc to localized string x from table "Localizable" in bundle (theBundle as «class furl»)
set aList to my decoupe(cantMake_loc, {"%1", "$2"})
set aList to aList & {"real", "of application \"Safari\"", " of window id", "«class bTab»"}
tell application "Safari" to set tabWinList to tabs of windows
try
tabWinList / 0
on error eMsg
set AppleScript's text item delimiters to aList
set tabWinList to text items of eMsg
set AppleScript's text item delimiters to linefeed
set tabWinList to tabWinList as text
set tabWinList to words of tabWinList
repeat with theWord in tabWinList
try
set contents of theWord to theWord as integer
on error
set contents of theWord to "null"
end try
end repeat
end try
set tabWinList to integers of tabWinList
#=====
on decoupe(t, d)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set l to text items of t
set AppleScript's text item delimiters to oTIDs
return l
end decoupe
#=====
------------------------------------------------------------------------------
We may also convert your Satimage version into an ASObjC one.
------------------------------------------------------------------------------
# ASObjC version
------------------------------------------------------------------------------
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
tell application "Safari" to set tabWinList to tabs of windows
try
tabWinList / 0
on error eMsg
set tabWinList to its findPattern:"\\d+" inString:eMsg
end try
------------------------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------------------------
on findPattern:thePattern inString:theString # borrowed to Shane STANLEY
set theNSString to current application's NSString's stringWithString:theString
set theOptions to ((current application's NSRegularExpressionDotMatchesLineSeparators) as integer) + ((current application's NSRegularExpressionAnchorsMatchLines) as integer)
set theRegEx to current application's NSRegularExpression's regularExpressionWithPattern:thePattern options:theOptions |error|:(missing value)
set theFinds to theRegEx's matchesInString:theNSString options:0 range:{location:0, |length|:theNSString's |length|()}
set theResult to {} -- we will add to this
repeat with i from 1 to count of theFinds
set theRange to (item i of theFinds)'s range()
set end of theResult to (theNSString's substringWithRange:theRange) as string
end repeat
return theResult
end findPattern:inString:
------------------------------------------------------------------------------
Yvan KOENIG running Sierra 10.12.5 in French (VALLAURIS, France) dimanche 21 mai 2017 11:12:32