[CS3 JS] Working with two documents of the same name

I work with sets of documents that use standardized names. I'm trying to write a script that compares two documents from different sets. Because the source and the target documents both have the same name, I've encountered some disturbing behavior that reminds me of the app.activeWindow bug that Dave has written about. (
Dave Saunders, "Scripting FAQ as Wiki" #14, 15 Oct 2007 12:19 pm)
To perform the comparison, I have to grab a reference to the same region of text in both documents, as offset from regular landmarks. I was just patting myself on the back for figuring out the "story.characters.itemByRange(begin, end).texts[0]" acrobatics required, when I discovered that my text objects were magically "dissolving" into invalid objects.
After a lot of debugging and attempts to hack around the problem (i.e. storing the text begin/end indices and not grabbing the text object until the last possible moment), I've narrowed it down to the references to the source and target documents. I've watched the reference variable to the source document *change* to instead reference the target document when I start accessing the target document object. Once this happens, any text objects belonging to the source document become invalid, as if the source document had been closed.
Is there any way around this? I've thought about temporarily saving the files to different names, but I haven't tried it yet.
Here's a script that demonstrates the problem (you'll have to find your own same-named documents if you want to run it):
var source = "/Users/deyk/Desktop/test/source";
var target = "/Users/deyk/Desktop/test/target";
function findChapters(in_doc) {
app.findGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.appliedCharacterStyle = "chapter-num";
app.findGrepPreferences.findWhat = "\\d+";
return in_doc.findGrep();
var sdoc = app.open(File(source+"/01.Genesis.indd"));
var s_file_start = sdoc.fullName;
var s_chs = findChapters(sdoc);
var s_story = s_chs[0].parentStory;
var s_txt = s_story.characters.itemByRange(s_chs[0].index,
s_chs[1].index-1).texts[0];
var tdoc = app.open(File(target+"/01.Genesis.indd"));
// At this point, sdoc now references tdoc instead.
// s_txt, s_story, and s_chs become invalid objects.
var t_file_start = tdoc.fullName;
var t_chs = findChapters(tdoc);
var t_story = t_chs[0].parentStory;
var t_txt = t_story.characters.itemByRange(t_chs[0].index,
t_chs[1].index-1).texts[0];
var s_file_end = sdoc.fullName;
if (s_file_end.name != s_file_start.name) {
var result = "What a nasty bug!";
"Finished";

I've tried saving the document to a temporary name, and it works satisfactorily:
function openFileAsTemp(a_file) {
var tmp_folder = Folder.temp.fullName;
var date = new Date();
var temp_file = File(tmp_folder+'/'+date.valueOf()+'_'+a_file.name);
var doc = app.open(a_file);
doc = doc.save(temp_file);
return doc;

Similar Messages

  • Apex mixes applications working with two windows at the same time

    Hi all, while developing in Apex I have found the following problem:
    Working with two different applications at the same time, the browser goes from one to another indistinctly.
    To reproduce the problem:
    1. Open the same application builder in two different Firefox windows
    2. Open a different application in each window (In my case: application 103 in window1 and application 105 in window2)
    3. Go to shared components in both windows (window1 first)
    - window1 breadcrumbs show: Home > Application Builder > Application 103 > Shared Components
    - window2 breadcrumbs show: Home > Application Builder > Application 105 > Shared Components
    4. Click in any shared component in window1 (Templates, Authentication Schemes...)
    - window1 breadcrumbs show: Home > Application Builder > Application *105* > Shared Components > Templates (Application 105 instead of 103)
    Is it a bug? I have read the known issues [[Here]|http://www.oracle.com/technetwork/developer-tools/apex/downloads/apex402knownissues-189793.html] but it does not appear.
    Related Data:
    Application Express version 4.0.2.00.07
    Firefox 3.6.15
    SO: Windows XP
    The error is not reproduced with IE7. I have not tested any other browser.
    Regards,
    Molina

    If you tried opening up two pages in the same application each of which modifies the same page items, you would notice the same issue.
    This is because, in a session there is only one set of values for page items(or application items) and every parallel call to the same page would update the same bind variables.
    Now the development environment or Apex Builder is also an apex application , and when try and open up the pages as you mentioned, they both access the same Application Builder page and sets/resets any existing values for those variables(and maybe cookies too if they are being used) , hence the 'mixing up'.
    If that didn't convince you, check the URL of both the pages when you load them, they should show the same page number ( f?p=APP_ID:PAGE_NUMBER syntax). Imagine if the same approach was done with one of your application pages, say an edit form opened from a report with multiple records in multiple tabs like what happened with this case: {message:id=9346663}
    So this really isn't a bug in a way, because that is how session states in apex is/was maintained. Ofcourse if they used another kind of development platform for building pages, it may have been avoided, but thats an altogether different point in itself.

  • 3.2.3;Swing app.; Cannot work with two applications at the same time.

    Hi guys,
    I bring this problem here may somebody experienced that.
    I developed two client side applications(applets) with JDev3.2.3.
    Locate them on Apache/Tomcat. There is also a
    Index.html file with two links, so when user clicks on
    each link the associated application will downloaded
    on his/her PC and ready to work. (In index.html I used
    JavaScript function window.open(…) to load the applications)
    Now please see this scenario:
    1-I ran/loaded both application in two separate
    browsers(IE5.5). And tried to work with them(minimized
    one and work with another). Soon I faced unexpected
    frizzing/locking or very slow running on both
    applications.
    2-Then closed/killed one of them(killed IE). Then
    re-executed same application again. The application
    loaded with the last activated screen . Seems it never
    killed and it was still alive.
    3- The only way to successfully working is one by one.
    Means execute & work with one, then kill that, and
    then execute and work with another. Which is not expected
    in the Windows enviroment.
    To Debug:
    When both applications were running(each on it’s own
    IE), I opened the Task Manager and saw there was only
    one IEXPLORER.EXE was running, also there was only one
    Java VM (a little bird icon) on right-bottom of the
    screen.
    I believe this causes the problem. Seems they both
    running in the same session. Since I opened two
    applications in two IE I was expected to see two
    IEXPLORER.EXE with two JVM. Am I right? Do you think
    so?
    Any way, Now I am seeking to find the solution. My
    primary mind says probably I should not use
    window.open(..) in index.html to load the
    applications.
    Would appreciate any command on this.

    Same thing with me! My microphone doesn't even register in anything but ventrilo!
    It's dri'ves me NUTS! I bought the card (xfi fatalty) for a really good price, but I almost regret even looking into the soundcard because of this bug. I know Vista is a new operating system..but I figure'd this kind of update should have been noticed MUCH earlier..
    Please creative, can you fix this?
    On another note..is there a sound quality difference between using an x-fi in vista vs xp?
    *not meaning to thread jack*
    finally..
    you should probably close the other thread.. You made two, you know.

  • How can I work with two images at the same time?

    I have downloaded Photoshop Elements 10 and I can not find the buttons for Minimize or Reset for the image. If I rightclick the miniature those options are grey. If I open two images so I have two miniatures in the holder and then go to Windows and Images the option Show Overlapping is grey but I can show Side by side. Then I can only shut down the images.
    Thanks for help
    Bibbi

      Open the Editor and on the menu bar click:
    Edit à Preferences à General
    Check the box “Allow Floating documents in Full Edit Mode” and click OK.
     

  • HT3819 Can you home share with two libraries on the same computer?

    Can home share be used with two libraries on the same computer?

    iTunes must be running for home sharing to work.  There is no way to have home sharing running simultaniously for two users on the same computer.
    Simply add the media files using File > Add File/Folder option in iTunes.

  • I purchased Adobe photoshop elements II and Adobe premiere elements II. They are both on one disc. My computer crasded and I had to reload Windows. I only have one serial number and it only works with photoshop II. The same serial number will not work for

    I purchased Adobe photoshop elements II and Adobe premiere elements II. They are both on one disc. My computer crasded and I had to reload Windows. I only have one serial number and it only works with photoshop II. The same serial number will not work for Premiere. I dont have any other serial numbers. What do I do???

    Static_Unit
    I am getting a bit concerned about what is happening in your situation. Yesterday you posted your question in at least two different forums, one of them being here in the Premiere Elements Forum.
    Don't Have Serial Number for Premiere, Only Photoshop?
    Wherever you posted, the reply was to contact Adobe via its Adobe Chat. It is the only one who can sort out this matter for you.
    In the thread cited above I offered to help you with the difficulties that you were having visualizing the Adobe Chat in its web page. I was waiting for your follow up on that in the above thread. Instead, I find your same question in a new Adobe Premiere Elements Forum thread this afternoon with no refer the prior threads or prior recommendations given you.
    I will also mention again...when you buy the Photoshop Elements and Premiere Elements bundled in one packaging and with installation files for each on the same installation disc, each program has its own serial number. The Photoshop Elements serial number does not work for Premiere Elements and vice versa. The serial numbers are on labels on a box which houses the installation disc envelope(s). So, if you purchased both programs and found the Photoshop Elements serial number, then the Premiere Elements serial number should be in a label right underneath the label with the serial number for Photoshop Elements. I recall writing this in your yesterday's thread on this matter.
    The moderator will no doubt be along shortly to close or delete this thread. So, just in case, please bookmark your yesterday's thread cited above so that we can continue this communication which is trying to help you.
    Thanks.
    ATR

  • HT3529 will imessaging work on two iphones using the same apple id

    will imessaging work on two iphones using the same apple id

    It will. If the two phones are used by two different people, however, you will need to implement some careful management of your iMessage settings to ensure that you don't each receive each-other's messages. It is a much safer option to use different Apple IDs for each individual.
    On iOS devices, you are able to use separate Apple IDs for iMessage and Facetime, iCloud, and the iTunes and App Stores.

  • How to share iphoto with two users in the same imac maverick

    I can´t find the way to share iphoto/itunes with two users in the same imac with maverick software

    In conclusion, the new software is worse than the old one, really?  Because in my old mac I could share easily without copy with an external USB
    It's not iPhoto that dropped the ball but the system.  I believe it was Mavericks that broke the Shared folder compatibility for iPhoto, not iPhoto itself.
    Also having the library on an external HD is a good way of freeing up space on the boot drive to assure optional system and application performance.

  • If I use the remote with two macbooks in the same room both of them answer

    If I use the remote with two macbooks in the same room, the two of them answer. So if the person sitting near me is doing something else I interrupt them... this is quite annoying!
    Does anyone know how to solve this? Should I report it as a bug? Where?

    Hi Carito,
    It is not a bug, all you have to do is pairing them.
    Here is the link:
    http://docs.info.apple.com/article.html?artnum=302545
    and:
    http://docs.info.apple.com/article.html?path=Mac/10.4/en/mh2275.html
    Good Luck.

  • What is the best way to work with Word documents in The InDesign CS4???

    I work in Microsoft Word 2007 and all my documents have *.doc format.
    What is the best way to work with Word documents in InDesign CS4???
    David Blatner says to avoid copying and pasting text from Word instead of placing it (Ctrl+D).
    How about pasting RTF or Text Document???
    I want to make book's layout in ID CS4 and its main feature is that there is the left page with text and the right - with graphics.
    So, as I understand to place the text on each page I must create for example 70 Word documents and place each item on 70 left pages???
    It loks like wasting time. I sthere another way of making such layout???  What kind????

    It's best to place any text.
    You can have all of your text in one file and use auto-flow to add threaded text frames and pages as required (Hold down the Shift key when you click the loaded text cursor), but it's a little non-standard to have the thread only on one side of the spread from the auto-flow perspective, so you'll have to set up properly.
    This is one case where a master text frame will work to your advantage. On your master page spread, add a text frame to the left page, but not to the right (or at least not threaded to one on the right -- for some other project you might actually want two independent text threads). Hold the loaded cursor over a frame on the left side of a document page and auto-flow. ID will add new spreads as necessary, but only put the text on the left side.
    Peter

  • Can I work on two items on the same screen

    I currently am working with two monitors so that i can have two items open side by side.  Is it possible to do the same with just one Apple monitor?

    Yes.  Just open two windows which can be side by side.

  • Can two bands use the same name on iTunes?

    Hi, I'm in a band that uses the same name as another band listed on iTunes.
    Can two bands with the same name be listed on iTunes? We hope to eventually have an album for sale on the site and I'd like to know now if it's going to be a problem.

    Of course it will be a problem. You simply can not have two bands with the same name. I can think of MANY bands that had to change their names (either completely or just for certain countries) because the name was already taken. Blink (Blink-182), Bush (Bush X), The Beat (The English Beat), Yazoo (Yaz), and the list goes on and on.
    Your band better start brain storming for a new or modified name.
    Patrick

  • Album Shuffle Doesn't Work Properly When Albums Have The Same Name

    I'm using the latest versions of iTunes 7.0.2 and 5.5G iPod v1.2.1, but this problem has existed in (as far as I know) all iPods to date. It certainly still continues to occur on the latest iPod.
    Example of the problem: I have many Albums by different Artists. I listen to them on my iPod by using "Album Shuffle" which plays the contents of an album in sequential order, but successive albums in random order. This is good when it works. However, iTunes and iPod have a problem when more than 1 album has the same name. So, let's say you have 3 albums by 3 different groups (Band A, B, and C), all called "Greatest Hits". The expected behaviour is that "Greatest Hits by Band A will play tracks 1-10, then another random album, and then sometime later, the album "Greatest Hits" by Band C will play tracks 1-15. That would be good, but this does not happen. Here's what actually happens:
    Some Album / Band X / Track 14
    Some Album / Band X / Track 15
    Some Album / Band X / Track 16
    Greatest Hits / Band A / Track 1
    Greatest Hits / Band B / Track 1
    Greatest Hits / Band C / Track 1
    Greatest Hits / Band B / Track 2
    Greatest Hits / Band A / Track 2
    Greatest Hits / Band C / Track 2
    Greatest Hits / Band B / Track 3
    Greatest Hits / Band C / Track 3
    Greatest Hits / Band A / Track 3
    ... (until all "Greatest Hits" tracks by Bands A, B, and C have finished)
    Another Album / Band Z / Track 1
    Another Album / Band Z / Track 2
    Another Album / Band Z / Track 3
    As you can see, the iPod treats all 3 "Greatest Hits" as one humungous album. Now, until version 7, even iTunes appeared to be pretty confused about this, but with the latest version added the "Album Artist" tag (which I've applied correctly to all tracks in my Library), so that it can identify albums as separate entities properly, even if they have the same name. (This was necessary for Cover Flow to work.) Sadly, this logic has not made it to the iPod, and we still have the crazy playback situation above.
    Since the first day I bought my first iPod back in 2002, I've always used Album Shuffle, and this has always been a problem. I was surprised to find that even the latest iPod still hasn't fixed this, even though iTunes seems to have. Apple, please could you fix this?
    iPod 5.5G, iTunes 7.0.2   Mac OS X (10.4.8)  
    Power Mac G5 Dual 2.3 GHz   Mac OS X (10.4.8)  

    BTW, I'm not looking for workarounds that involve renaming albums. What if I have 158 "Greatest Hits" albums?

  • Sync a phone with 2 Macs (having the same name)

    Hi,
    The question is on the title:
    is there a problem to use 2 Macs HAVING THE SAME NAME (I.E. my name) with a single phone ?
    I hope a clearly asked my question (my frenchy english is sometimes clumsy).
    Where can I find a omplete documentation of iSync.
    Thank you all

    Welcome to Apple Discussions.
    The short answer is yes, this approach is problematic and can result in severe data corruption on not only your mobile handset, but on both computers. The name of each computer is immaterial: iSync is not intended to support the use of a device as a 'data storage' go-between to equalize the contents of contact, calendaring and tasks records on two or more Macintosh desktop or portable computers.
    Instead, you should synchronize multiple Macintosh computers using:
    • .Mac Sync with a .Mac account
    • MySync from MildMannered Industries (technology acquired by Mark/Space)
    • the not-yet released SyncTogether from Mark/Space
    More information about these options is available here:
    http://www.mildmanneredindustries.com/mysync
    http://www.markspace.com/synctogether.php

  • Itunes installs with many folders of the same name,why?

    I have uninstalled and installed 3 times.  Each time it loads with many folders on left column with the same name.  What is resolution?

    Do you mean playlist folders or playlists? Reinstalling iTunes does not rebuild the library so it won't tidy up the structure of your library. Recent builds of iTunes have imported any m3u playlists found when scanning the media folders which can cause problems if you've previously generated playlists for all your albums with other software, though in this case the playlists would have different names.
    Have you subscribed to iTunes Match? There is a bug that can sometimes create hundreds of duplicate empty playlists. I've two scripts which might help you clean up: KillEmptyPlaylists and KillTopLevelPlaylists. This post describes a technique for resetting iTunes Match to stop it happening again.
    tt2

Maybe you are looking for