How Do I Select "Favorites" on Emoji & Symbols Window?

foundation
asobjc

(Jim Underwood) #1

I need some help from you UI scripting Gurus.

I need to automate selection of the “Favorites” button/tab/panel in the Emoji & Symbols (aka Special Characters) window:

image

SD6 has been a great help in determining the UI tree, but after several hours of trial and error, I still can’t make the below script work.

Any ideas/suggestions?

From UI Browser

AppleScript

tell application "System Events"
  tell its application process "CharacterPalette"
    set oWin to window "Characters"
    tell its window "Characters"
      tell its splitter group 1
        tell its splitter group 1
          tell its scroll area 1
            tell its table 1
              tell its row 2
                set oFav to UI element "Favorites"
                tell oFav
                  set value of attribute "AXEnabled" to true
                  set value of attribute "AXSelected" to true
                  set value of attribute "AXFocused" to true
                  perform action "AXPress"
                  click
                end tell
              end tell
            end tell
          end tell
        end tell
      end tell
    end tell
  end tell
end tell


(Jonas Whale) #2

Try this:

tell application "SSD MacPro:System:Library:Input Methods:CharacterPalette.app:"
	
	activate
	tell application "System Events"
		tell process "Emoji et symboles"
			
			select row 2 of table 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "Caractères"
			
		end tell
	end tell
	
end tell

(Jim Underwood) #3

Thanks, Jonas. Using select was the secret I was missing. :+1:

Here’s my script, based on yours, that works for me, in the USA with English language.
Script Debugger 6.0.5 (6A205) on macOS 10.11.6

### TESTED on Script Debugger 6.0.5 (6A205) on macOS 10.11.6 ###


### This does not appear to be needed, nor useful ###
#      It does NOT show the Characters window

--tell application "Macintosh HD:System:Library:Input Methods:CharacterPalette.app" to activate

### First, Manually Show Characters Window ###
--    tell app CharacterPalette.app to activate does NOT show window
--    Usual shortcut is ⌃⌘SPACE

tell application "System Events"
  tell process "Emoji & Symbols"
    
    ## You can also use:
    # tell process "CharacterPalette"
    
    --- THIS WORKS FINE ---
    select row 2 of table 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "Characters"
    
    
    ### ANY IDEAS on How to use row name to Select, like this? ###
    --    Doesn't work
    --  select (row whose name is "Favorites") of table 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "Characters"
    
  end tell
end tell

Any ideas on how to:

  1. Display Emoji & Symbols window independent of the app?
    (⌃⌘SPACE does NOT work in all apps)
    .
  2. Use the group name, like “Favorites” to select the group in the window “Characters”

(Jonas Whale) #4

Sorry, there’s no way to do this as the “Favorites” UI is part of the row.

To activate the palette, you can use the keystroke command (assuming you did not change the default shortcut).

tell application "System Events"
	keystroke space using {command down, control down}
	delay 0.4
	tell process "Emoji et symboles" -- or tell process "CharacterPalette"
		try
			splitter group 1 of splitter group 1 of window 1
			select row 2 of table 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1
		end try
	end tell
end tell

[I don’t need to tell you that the `delay` depends on your machine speed.]


(Jim Underwood) #5

Thanks, @ionah.

BTW, here is a cool script by @Tom in the Keyboard Maestro forum to toggle the Emoji window show/hide, which avoids use of the shortcut key. It is very fast.

Of course, it is easy enough to add the code to select the “Favorites” (or any other) group in the window.


(Jonas Whale) #6

Good job!

But there’s some point I must argue:

I prefer not to rely on menu names because like most of scripters, my apps are not always in English.
(“Edit” -> “Edition”, “Emoji & Symbols” -> “Emoji et Symboles”)

Here is what should be my version of the script:

tell application "System Events"
	try
		tell process "CharacterPalette" to click button 2 of window 1
	on error
		tell (first process whose frontmost is true) to click menu item -1 of menu 4 of menu bar 1
		delay 0.4
		try
			tell process "CharacterPalette" to select row 2 of table 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1
		end try
	end try
end tell

(Jim Underwood) #7

Good point. However, the position in the Edit menu can vary by app. But, if the “Emoji” menu item is always the last menu item, then your approach should work.

Is the position of the “Emoji” menu item forced to be last by the macOS, or can the app developer override this?


(Jim Underwood) #8

@ionah and @Tom:

Outlook 2011 is one exception to this. The Emoji menu item (called “Special Characters…” in Outlook) is NOT the last menu item:

image


(Jim Underwood) #9

So, since I can’t rely on the “Emoji & Symbols” menu item to be the last in the Edit menu, this is the best I can do: Pick from a valid list.

Please improve if you can.

property ptyScriptName : "Show Emoji & Symbols Window"

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

property LF : linefeed

### REVISE to Include Emoji Menu Names in your System ###
property validEmojiMenuNames : {"Emoji & Symbols", "Special Characters...", "Emoji et Symboles"}

tell application "System Events"
  
  --- OPEN Emoji & Symbols Window ---
  --   (Menu Item MUST be in Above Property List)
  
  set frontProcess to first process whose frontmost is true
  tell frontProcess
    
    --- GET LIST of NAMES in FrontMost App EDIT Menu ---
    set menuItems to name of every menu item of menu 4 of menu bar 1
    
    --- DOES App EDIT Menu Contain a Valid Emoji Name? ---
    
    set iMenuItemIndex to 0
    repeat with aMenuItem in validEmojiMenuNames
      set iMenuItemIndex to my getIndex((aMenuItem), menuItems)
      if (iMenuItemIndex ≠ 0) then exit repeat -- found it!
    end repeat
    
    if (iMenuItemIndex ≠ 0) then
      click menu item iMenuItemIndex of menu 4 of menu bar 1
    else
      
      --- Emoji & Symbols Menu Item NOT FOUND ---
      do shell script "afplay /System/Library/Sounds/Basso.aiff" -- is there a better way?
      
      set msgStr to "❯❯❯ ERROR ❮❮❮" & LF & "Unable to Show Emoji & Symbols Window" & LF & LF & ¬
        "Emoji/Character Menu Item NOT Found from available list: " & LF & my joinListToStr(validEmojiMenuNames, ", ")
      display dialog msgStr with title ptyScriptName
      
    end if
    
  end tell -- frontProcess
  
end tell -- "System Events"

on getIndex(pItem, pList) -- @List @Index
  local idx, i, lenList
  
  set idx to 0
  set lenList to length of pList
  set pItem to contents of pItem
  
  repeat with i from 1 to lenList
    if (pItem = (contents of item i of pList)) then
      set idx to i
      exit repeat
    end if
  end repeat
  
  return idx
  
end getIndex

on joinListToStr(pList, pDelim)
  set textDelimSave to AppleScript's text item delimiters
  set AppleScript's text item delimiters to pDelim
  set newString to pList as string
  set AppleScript's text item delimiters to textDelimSave
  return newString
end joinListToStr


(Jonas Whale) #10

For my part, I would add a shortcut to the menu of Outlook and use the version of post #4.

To play a sound:

 use framework "Foundation"

(current application's NSSound's soundNamed:"Purr")'s play()

The sound name is case sensitive.


Playing a Sound with ASObjC
(Jim Underwood) #11

Thanks, I like that solution for sounds.

What sounds are available? Those in the /System/Library/Sounds folder?


(Jim Underwood) #12

Here is a script that does the job without using KM:

property ptyScriptName : "Show Emoji & Symbols Window & Select Favorites"
property ptyScriptVer : "3.0"
property ptyScriptDate : "2017-11-05"
property ptyScriptAuthor : "JMichaelTX"


use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

property LF : linefeed
property isKMErunning : false -- is Keyboard Maestro Engine running?
property validEmojiMenuNames : {"Emoji & Symbols", "Special Characters...", "Emoji et Symboles"} -- name as appears in Edit menu
property groupName : "Favorites" -- Emoji Folder to be selected

--tell application "System Events" to set isKMErunning to (exists process "Keyboard Maestro Engine")

--- Get Mouse Pos if KM is running, else Get Center of Frontmost Window ---
set {mouseX, mouseY} to my getMousePos()

tell application "System Events"
  
  --- OPEN Emoji & Symbols Window ---
  --   (menu item of Edit menu)
  
  set frontProcess to first process whose frontmost is true
  tell frontProcess
    
    --- GET LIST OF MENU ITEM NAMES IN EDIT MENU ---
    set menuItems to name of every menu item of menu 4 of menu bar 1
    
    --- GET INDEX OF EMOJI MENU ITEM ---
    
    set iMenuItemIndex to 0
    repeat with aMenuItem in validEmojiMenuNames
      set iMenuItemIndex to my getIndex((aMenuItem), menuItems)
      if (iMenuItemIndex ≠ 0) then exit repeat
    end repeat
    
    
    if (iMenuItemIndex ≠ 0) then
      
      --- OPEN EMOJI & SYMBOLS WINDOW ---
      click menu item iMenuItemIndex of menu 4 of menu bar 1
    else
      
      --- Emoji & Symbols Menu Item NOT FOUND ---
      set msgStr to "Emoji/Character Menu Item NOT Found from available list: " & my joinListToStr(validEmojiMenuNames, ", ")
      set msgTitleStr to ptyScriptName
      display notification msgStr with title msgTitleStr sound name "Basso.aiff"
      set msgStr to "❯❯❯ ERROR ❮❮❮" & LF & "Unable to Show Emoji & Symbols Window" & LF & LF & msgStr
      display dialog msgStr with title msgTitleStr
      
    end if
    
  end tell -- frontProcess
  
  
  if (iMenuItemIndex ≠ 0) then -- menu item was found
    
    --- MOVE WINDOW AND SELECT DESIRED FOLDER ---
    
    --- Pause Until Window is Open ---
    set {elapTime, successBool} to my pauseUntilWin("Characters", "CharacterPalette", 2)
    
    tell process "CharacterPalette"
      
      --- MOVE WINDOW BELOW MOUSE ---
      tell window 1 to set position to {mouseX + 10, mouseY + 20}
      
      --- GET GROUP LIST ---
      set groupList to name of first UI element of rows of table 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1 -- "Characters"
      
      set groupIndex to my getIndex(groupName, groupList)
      
      if (groupIndex ≠ 0) then
        
        --- SELECT USER REQUESTED GROUP ---
        select row groupIndex of table 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1 --  "Characters"
        
      else
        
        --- GROUP NAME NOT FOUND ---
        set msgStr to "Emoji/Character Group NOT Found: " & groupName
        set msgTitleStr to ptyScriptName
        display notification msgStr with title msgTitleStr sound name "Basso.aiff"
        
      end if
      
    end tell -- process "CharacterPalette"
    
  end if -- (iMenuItemIndex ≠ 0)
  
end tell


--~~~~~~~~~~ END OF MAIN SCRIPT ~~~~~~~~~~~~~~~~~~~

on getMousePos()
  local mousePosStr, mouseX, mouseY
  
  if isKMErunning then
    
    tell application "Keyboard Maestro Engine" to set mousePosStr to process tokens "%CurrentMouse%"
    set {mouseX, mouseY} to my splitStrToList(mousePosStr, ",")
    
  else
    --- NEED ALTERNATE METHOD TO GET MOUSE POS ---
    -- For Now, Use Center of Frontmost Window --
    set {mouseX, mouseY} to my getWinCenter()
    
  end if
  
  return {mouseX, mouseY}
  
end getMousePos

on getWinCenter()
  local posWin, sizeWin, centerWin, nameProcess
  
  tell application "System Events"
    set frontProcess to first process whose frontmost is true
    set nameProcess to name of frontProcess
    tell frontProcess
      set oWin to front window
      set posWin to position of oWin
      set sizeWin to size of oWin
    end tell
  end tell
  
  set centerWin to {(item 1 of posWin) + ((item 1 of sizeWin) / 2), (item 2 of posWin) + ((item 2 of sizeWin) / 2)}
  
  return centerWin
end getWinCenter

--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
on getIndex(pItem, pList) -- @List @Index
  (*  VER: 2.0    2017-08-02
---------------------------------------------------------------------------------
  PURPOSE:  Get the Index (Item #) of a Item within a List
  PARAMETERS:
    • pItem    ║ any  ║ Item to Find.  Can be text, numeric, date, or list
    • pList    ║ text  ║ List to be searched.
  RETURNS:  integer  ║ Index number (0 if NOT found) 
  AUTHOR:  JMichaelTX
—————————————————————————————————————————————————————————————————————————————————
*)
  local idx, i
  
  set idx to 0
  set lenList to length of pList
  set pItem to contents of pItem
  
  repeat with i from 1 to lenList
    if (pItem = (contents of item i of pList)) then
      set idx to i
      exit repeat
    end if
  end repeat
  
  return idx
  
end getIndex
--~~~~~~~~~~~~~~~ END OF handler getIndex ~~~~~~~~~~~~~~~~~~~~~~~~~


on splitStrToList(pString, pDelim)
  
  set textDelimSave to AppleScript's text item delimiters
  set AppleScript's text item delimiters to pDelim
  
  set newList to text items of pString
  
  set AppleScript's text item delimiters to textDelimSave
  
  return newList
  
end splitStrToList


on joinListToStr(pList, pDelim)
  
  
  set textDelimSave to AppleScript's text item delimiters
  set AppleScript's text item delimiters to pDelim
  
  set newString to pList as string
  
  set AppleScript's text item delimiters to textDelimSave
  
  return newString
  
end joinListToStr


on pauseUntilWin(pWinTitle, pProcessName, pMaxTimeSec)
  (*
    Usage Note:  It is best to test for existance of the literal process BEFORE
                      calling this handler.  For example:
                      if (exists process "CharacterPalette") then
  *)
  local startTime, elapTime, errMsg
  
  set LF to linefeed
  set successBool to true
  
  set startTime to current application's NSDate's |date|()
  
  tell application "System Events"
    repeat until window pWinTitle of process pProcessName exists
      set elapTime to -(startTime's timeIntervalSinceNow())
      
      if (elapTime > pMaxTimeSec) then
        set successBool to false
        set errMsg to "Max Time of " & pMaxTimeSec & " sec exceeded waiting for:" & LF & ¬
          "Window: " & pWinTitle & LF & "Process: " & pProcessName
        --log errMsg
        display notification errMsg
        exit repeat
      end if
      delay 0.1
    end repeat
  end tell
  
  set elapTime to (-(round ((startTime's timeIntervalSinceNow()) * 100)) / 100.0)
  
  return {elapTime, successBool}
  
end pauseUntilWin


(Jean Christophe Helary) #13

Jim, thank you for the pointer to this thread !


(Jim Underwood) #14

Here’s a better script, based in large part on the script by @koenigyvan (Yvan):

property ptyScriptName : "Toggle Show/Hide of Emoji Window"
property ptyScriptVer : "3.1"
property ptyScriptDate : "2017-11-07"
property ptyScriptAuthor : "JMichaelTX" -- based on script by Yvan Koenig
# While this script is based largely on scripts by others, all errors are mine.

(*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PURPOSE:
  • Quickly Show/Hide the Emoji & Symbols Window
    that should work in any macOS language

REQUIRED:
  1.  macOS 10.11.6+ (may work on earlier versions, but I have not tested any other versions)
  2.  Mac Applications
      • System Preferences > Keyboard must be set to:
        "Show Keyboard, Emoji, & Symbol Viewers in menu bar"

REF:  This script is based largely on:

  1.  Yvan KOENIG, 2017-11-07, Show Emoji & Symbols GUI access -- ASUL
      http://lists.apple.com/archives/applescript-users/2017/Nov/msg00079.html
      
  2. Aviral Bansal, 2016-04-02, Speed up AppleScript UI scripting? - Stack Overflow
      https://stackoverflow.com//a/36370637/915019
      
  3. Thomas Floeren, 2017-11-07, Suggestion on ASUL to Use “killall System Events”
      http://lists.apple.com/archives/applescript-users/2017/Nov/msg00083.html
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*)

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation" -- don't really need this
use scripting additions

property LF : linefeed
property isKMErunning : false -- is Keyboard Maestro Engine running?
property groupName : "Favorites" -- Emoji Folder to be selected

tell application "System Events" to set isKMErunning to (exists process "Keyboard Maestro Engine")


--- Get the localized version of "Emoji" ---

set theSource to (path to library folder from system domain as text) & "Frameworks:Carbon.framework:Versions:A:Frameworks:HIToolbox.framework:"
set EmojiAndSymbols_loc to localized string "Emoji & Symbols" from table "Menus" in bundle (theSource as «class furl»)

--- TODO: Get Localized Version of "Favorites" ---

set favFolderName to "Favorites" -- folder on Emoji Window (not used in this version)
#?# set favFolderName to localized string favFolderName from ??? -- anyone know?
##TODO: Add code to select Favorites folder ##

-----------------------------------------------
--- PART 1.  Show the Emoji Viewer Menu Items
-----------------------------------------------

tell application "System Events" to tell process "SystemUIServer"
  
  set emojiViewerMenu to first item of ¬
    (menu bar items of menu bar 1 ¬
      whose value of attribute "AXDescription" = "text input")
  
  tell emojiViewerMenu
    
    --- Must Use "ignoring" and then "killall" to avoid ~5 sec Delay ---
    
    ignoring application responses
      perform action "AXPress" # Reveal the menu items
    end ignoring
    
  end tell -- emojiViewerMenu
  
  
end tell -- System Events -> "SystemUIServer"

-----------------------------------------------------------------
--- Finish the Process to Avoid Delay from Menu Press ---
-----------------------------------------------------------------
do shell script "killall System\\ Events"
delay 0.1

--------------------------------------------------------------------
--- PART 2. Click on the Emoji Item to Show/Hide the Emoji  Window
--------------------------------------------------------------------
(*
 NOW, Click on the Emoji Menu Item ---
    • This will toggle the display of the emoji window
    • The menu item always contains "Emoji"
    • But starts with "Show" when the window is not visible
    • Starts with "Hide" when the window is visible
*)


tell application "System Events" to tell process "SystemUIServer" to tell emojiViewerMenu
  
  tell menu 1
    
    try
      set toggleEmojiMenuItem to first menu item whose name contains EmojiAndSymbols_loc
      set emojiStatus to first word of (get name of toggleEmojiMenuItem)
      click toggleEmojiMenuItem
      set scriptResults to "OK" & LF & "Emoji & Symbols Window Status: " & emojiStatus
      
    on error
      key code 53 # Escape to hide the menu
      set errMsg to "The Emoji Viewer has NOT been enabled in System Preferences > Keyboard."
      set msgTitleStr to ptyScriptName
      display notification errMsg with title ptyScriptName sound name "Basso.aiff"
      
      set emojiStatus to "None"
      set scriptResults to "ERROR" & LF & errMsg
    end try
    
  end tell # menu 1
  
end tell

---------------------------------------------------------------
--- PART 3.  Move Emoji Window & Select Favorites ---
---------------------------------------------------------------

if (emojiStatus = "Show") then
  my moveEmojWin()
  my selectFavEmoji()
end if

return scriptResults

--------------------------------------------------------------------------
--~~~~~~~~~~~~~~~~~~~~~~~~~~~ END OF MAIN SCRIPT ~~~~~~~~~~~~~~~~~~~~~~~~
--------------------------------------------------------------------------

on moveEmojWin()
  --- MOVE WINDOW ---
  
  --- Get Mouse Pos if KM is running, else Get Center of Frontmost Window ---
  set {mouseX, mouseY} to my getMousePos()
  
  
  --- Pause Until Window is Open ---
  set {elapTime, successBool} to my pauseUntilWin("Characters", "CharacterPalette", 2)
  
  tell application "System Events"
    tell process "CharacterPalette"
      
      --- MOVE WINDOW BELOW MOUSE ---
      tell window 1 to set position to {mouseX + 10, mouseY + 20}
    end tell
  end tell
  
end moveEmojWin


on selectFavEmoji()
  
  tell application "System Events"
    tell process "CharacterPalette"
      
      --- GET GROUP LIST ---
      set groupList to name of first UI element of rows of table 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1 -- "Characters"
      
      set groupIndex to my getIndex(groupName, groupList)
      
      if (groupIndex ≠ 0) then
        
        --- SELECT USER REQUESTED GROUP ---
        select row groupIndex of table 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1 --  "Characters"
        
      else
        
        --- GROUP NAME NOT FOUND ---
        set msgStr to "Emoji/Character Group NOT Found: " & groupName
        set msgTitleStr to ptyScriptName
        display notification msgStr with title msgTitleStr sound name "Basso.aiff"
        
      end if
      
    end tell -- process "CharacterPalette"
  end tell -- "System Events"
  
end selectFavEmoji


on pauseUntilWin(pWinTitle, pProcessName, pMaxTimeSec)
  (*
    Usage Note:  It is best to test for existance of the literal process BEFORE
                      calling this handler.  For example:
                      if (exists process "CharacterPalette") then
  *)
  local startTime, elapTime, errMsg
  
  set LF to linefeed
  set successBool to true
  
  set startTime to current application's NSDate's |date|()
  
  tell application "System Events"
    repeat until window pWinTitle of process pProcessName exists
      set elapTime to -(startTime's timeIntervalSinceNow())
      
      if (elapTime > pMaxTimeSec) then
        set successBool to false
        set errMsg to "Max Time of " & pMaxTimeSec & " sec exceeded waiting for:" & LF & ¬
          "Window: " & pWinTitle & LF & "Process: " & pProcessName
        --log errMsg
        display notification errMsg
        exit repeat
      end if
      delay 0.1
    end repeat
  end tell
  
  set elapTime to (-(round ((startTime's timeIntervalSinceNow()) * 100)) / 100.0)
  
  return {elapTime, successBool}
  
end pauseUntilWin


on getMousePos()
  local mousePosStr, mouseX, mouseY
  
  if isKMErunning then
    
    tell application "Keyboard Maestro Engine" to set mousePosStr to process tokens "%CurrentMouse%"
    set {mouseX, mouseY} to my splitStrToList(mousePosStr, ",")
    
  else
    --- NEED ALTERNATE METHOD TO GET MOUSE POS ---
    -- For Now, Use Center of Frontmost Window --
    set {mouseX, mouseY} to my getWinCenter()
    
  end if
  
  return {mouseX, mouseY}
  
end getMousePos

on getWinCenter()
  local posWin, sizeWin, centerWin, nameProcess
  
  tell application "System Events"
    set frontProcess to first process whose frontmost is true
    set nameProcess to name of frontProcess
    tell frontProcess
      set oWin to front window
      set posWin to position of oWin
      set sizeWin to size of oWin
    end tell
  end tell
  
  set centerWin to {(item 1 of posWin) + ((item 1 of sizeWin) / 2), (item 2 of posWin) + ((item 2 of sizeWin) / 2)}
  
  return centerWin
end getWinCenter


on splitStrToList(pString, pDelim)
  
  set textDelimSave to AppleScript's text item delimiters
  set AppleScript's text item delimiters to pDelim
  
  set newList to text items of pString
  
  set AppleScript's text item delimiters to textDelimSave
  
  return newList
  
end splitStrToList


on joinListToStr(pList, pDelim)
  
  
  set textDelimSave to AppleScript's text item delimiters
  set AppleScript's text item delimiters to pDelim
  
  set newString to pList as string
  
  set AppleScript's text item delimiters to textDelimSave
  
  return newString
  
end joinListToStr

--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
on getIndex(pItem, pList) -- @List @Index
  (*  VER: 2.0    2017-08-02
---------------------------------------------------------------------------------
  PURPOSE:  Get the Index (Item #) of a Item within a List
  PARAMETERS:
    • pItem    ║ any  ║ Item to Find.  Can be text, numeric, date, or list
    • pList    ║ text  ║ List to be searched.
  RETURNS:  integer  ║ Index number (0 if NOT found) 
  AUTHOR:  JMichaelTX
—————————————————————————————————————————————————————————————————————————————————
*)
  local idx, i
  
  set idx to 0
  set lenList to length of pList
  set pItem to contents of pItem
  
  repeat with i from 1 to lenList
    if (pItem = (contents of item i of pList)) then
      set idx to i
      exit repeat
    end if
  end repeat
  
  return idx
  
end getIndex
--~~~~~~~~~~~~~~~ END OF handler getIndex ~~~~~~~~~~~~~~~~~~~~~~~~~

(koenigyvan) #15

I’m not sure that it’s what you really want but you may try:

set theBundle to (path to library folder from system domain as text) & "CoreServices:SystemFolderLocalizations:" set Favorites_loc to localized string "Favorites" from table "SystemFolderLocalizations" in bundle (theBundle as «class furl»)

Yvan KOENIG running High Sierra 10.13.1 in French (VALLAURIS, France) mercredi 8 novembre 2017 11:07:24

Oops, it seems that I used the wrong “balises” !


(Jim Underwood) #16

Thanks Yvan (@koenigyvan). That works perfectly. :+1: