0 Replies Latest reply on Sep 3, 2013 1:56 PM by DaveSofTypefi

    Using typeof to determine if selection is searchable

    DaveSofTypefi Level 2

      I don't know how useful this is, but it occurred to me at some point today that you can do this (particularly, the guts of the findable function):

       

       

      //DESCRIPTION: Demo of typeof to check for function
      
      
      (function(){
                if (app.documents.length > 0
                                    && app.selection.length == 1) {
                          if (findable(app.selection[0])) {
                                    setupFindText("abc", "123");
                                    app.selection[0].changeText();
                          }
                }
      
                function findable(obj) {
                          return typeof obj.findText == "function";
                }
      
      
                function setupFindText(find, change, wholeWd, caseSense, foots, hidLayers, lockedLayers, lockedStories, masters) {
                          app.findTextPreferences = null;
                          app.changeTextPreferences = null;
                          try { app.findTextPreferences.findWhat = find } catch(e) {};
                          try {app.changeTextPreferences.changeTo = change } catch(e) {};
                          app.findChangeTextOptions.properties = {
                                    caseSensitive:(caseSense == null ? false : caseSense),
                                    wholeWord:(wholeWd == null ? false : wholeWd),
                                    includeFootnotes:(foots == null ? false : foots),
                                    includeHiddenLayers:(hidLayers == null ? false : hidLayers),
                                    includeLockedLayersForFind:(lockedLayers == null ? false : lockedLayers),
                                    includeLockedStoriesForFind:(lockedStories == null ? false : lockedStories),
                                    includeMasterPages:(masters == null ? false : masters)
                          }
                } // end setupFindText
      }())