Getting Safari document title/location via Scripting Bridge fails

I'm trying to get the URL and document title from the topmost Safari document/tab. I have an AppleScript and an objective-c version using the Scripting Bridge framework.
Both versions work fine for most web pages, however when I open a Youtube video in full-screen mode, the Scripting Bridge based version fails (error below). The Apple Script works fine for "normal" and full-screen Safari windows.
Can anyone see what is wrong with the Scripting Bridge code below to cause it to fail for full-screen Safari windows?
Here the code (I omitted error checking for brevity):
AppleScript:
tell application "Safari"
# Give us some time to open video in full-screen mode
delay 10
do JavaScript "document.title" in document 0
end tell
Scripting Bridge:
SafariApplication* safari = [SBApplication applicationWithBundleIdentifier:@"com.apple.Safari"];
SBElementArray* windows = [safari windows];
SafariTab* currentTab = [[windows objectAtIndex: 0] currentTab];
// This fails when in full-screen mode:
id result = [safari doJavaScript: @"document.title" in: currentTab];
NSLog(@"title: %@", result);
Scripting Bridge error (with added line breaks):
Apple event returned an error. Event = 'sfri'\'dojs'{
'----':'utxt'("document.title"),
'dcnm':'obj '{ 'want':'prop',
'from':'obj '{ 'want':'cwin',
'from':'null'(),
'form':'indx',
'seld':1 },
'form':'prop',
'seld':'cTab' }
Error info = {
ErrorNumber = -1728;
ErrorOffendingObject = <SBObject @0x175c2de0:
currentTab of SafariWindow 0 of application "Safari" (238)>;
I could not find details about the given error code. It complains about 'currentTab' which shows that the JavaScript event at least made it all the way to Safari. I assume that the current tab receives the event, but refuses to run the JS code, because it is in full-screen mode. However, why does this work for an AppleScript? Don't they use the same code path eventually?
Thanks!
Rico

1) I have not yet looked into Apple events, but have read elsewhere that it is not the most fun thing to deal with. I might give it a shot after having tried 2 + 3
Not really, but your command isn't too complicated so it'd be quite doable using the AEBuild* functions/NSAppleEventDescriptor and AESendMessage. If you go the AEBuild* route, you can use AEDebug to sniff Apple events sent from AppleScript for clues - the AEPrint syntax is similar to that used by AEBuild* functions. Mostly it's just tedious; first learning to use the lower-level APIs, then writing the code for them.
2) Using NSAppleScript was actually my first approach, but having to compile each script before I run it seems a waste. Maybe I can try a pre-compiled script and hand in the JavaScript as a parameter.
That's the safe and efficient way to parameterize AppleScripts. Although unless you're doing this to support user-supplied scripts, by the time you've packed what you need into an NSAppleEventDescriptor, a bit more code and you could probably send it directly to Safari yourself.
3) I had tried ASTranslate in the past. I have not actually compiled the generated code, but seeing this makes me wonder about the difference between the Apple Script and Scripting Bridge.
I've written about that in various places, e.g.:
http://stackoverflow.com/questions/1309958/avoiding-applescript-through-ruby-rb- appscript-or-rubyosa/1316563#1316563
Basically, Apple event IPC is RPC plus first-class queries, not OO as a lot of folks assume. AppleScript's OO-like syntax is a bit of a red herring, and the AS interpreter uses various tricks (e.g. implict gets) to further this illusion. So it looks and feels like OO, but only up to a point, and beyond that folks get totally confused when it does something decidedly un-OO. Hence AppleScript's reputation amongst professional programmers as being confusing and unpredictable. (It's actually reasonably straightforward and predictable one you know how it really works; it's just that figuring it out for yourself takes a lot of time and effort, since it's completely messed with your preconceptions by then. Ugh.)
Apple had an opportunity to learn their lessons from AS's approach, but whether due to politics, hubris or naivety they decided to dress up SB to look even more Cocoa-/OO-like. Which just means there's a bigger impedance mismatch between the SB API and the AE API hidden beneath the surface. So the abstractions are thicker and leakier, and the obfuscations more impenetrable when you do run into problems. By comparison, objc-appscript minimizes the syntactic sugar and wears much of Apple events' inherent weirdness on its sleeve. So while it takes a bit of getting used to if you're from an OO background, once you do get the hang of it it (nearly always) just works.

Similar Messages

  • Document Title Split String Script to Incorporate in an If Statment

    Hello,
    I have a console script which will extract the file extension from the title in the document properties:
    firstWord = this.info.Title.split("."); event.value = firstWord[1];
    Example document title is:  DWGTest.idw
    After the script is run from the console it will show the file extension correctly as:  idw
    I now need to incorporate the script with an if statement and then perform an action.
    However after the script is run I get an syntax error.
    Can anyone please advise how I can modify the script to work correctly?
    // If the title in the document properties contains the file extension idw then create a signature field
    firstWord = this.info.Title.split("."); event.value = firstWord[1];
    if (firstWord == "idw")
    var numpages = this.numPages;
    for (var i=0; i < numpages; i++)
    var a = this.addField("Chk R1", "signature", 0,
    [1093, 119.5, 1054.5, 136.5]);
    Any assistance will be most appreciated.
    Thank you.

    Thank you very much for your help, George.
    The script now works, and if the title of the document contains idw as a file extension the signature field will be added.
    In regards to the value of the co-ordinates, the document is an A1 sized drawing which originated in inventor.  Hence the idw file extension.
    I will be adding to the script if statement shortly to include dwg file extensions for Autocad which will have slightly different co-ordinates for the signature field to that of the inventor drawing.
    var firstWord = info.Title.split(".")[1];
    if (firstWord === "idw") {
    addField("Chk R1", "signature", 0, [1093, 119.5, 1054.5, 136.5]);
    Thanks once again, your assistance is most appreciated. 

  • How to get name of the slicer via script

    Hi Gurus,
    I was wondering if we could get the name of the slicer added in IR Query section, via script ??
    That is, I have a bqy connecting to Essbase OLAP.
    Now I am adding a slicer in OLAP Section via script.
    For Ex : ActiveDocument.Sections["Query2"].Slicers.Add('Market.Gen3,Market' , 'Market.LA')
    Now,for some reason, I wanted to retrieve the name of the slicer I added and assign it to a variable. Is this possible ?? I couldn't see any option for this. Please help me out if any one has done this before ?
    Thank You,
    Aji

    Sethil,
    Use your date(let us say Date1) instead of sy-datum.
    CALL FUNCTION 'MONTH_NAMES_GET'
    EXPORTING
    LANGUAGE = SY-LANGU
    IMPORTING
    RETURN_CODE =
    TABLES
    MONTH_NAMES = itab_month
    EXCEPTIONS
    MONTH_NAMES_NOT_FOUND = 1
    OTHERS = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    READ TABLE itab_month
    WITH KEY MNR = date1+4(2).
    itab_month-LTX will contain the value you are looking for
    Good luck
    Raghava

  • ITunes Music Locations - controlling workstations remotely via script?

    I do storage administration at a company with over 2000 users scattered across the globe. Predictably, at least have use iTunes. We redirect the "My Documents" folder to a network location to force the backup of critical project data. This creates a huge problem for us. iTunes defaults to using the My Music folder in My Documents. This means we are storing and backing up at least 1TB of music.
    I have found that iTunes stores its configuration in xml files in the application data directory in the user profile. I cannot readily figure out where in this file the location is recorded.
    Has anyone confronted this problem, and if so, is there a way to control iTunes installs remotely to set the music folder location, via script, GPO or anything at all?

    The library location is indeed stored in the iTunesPrefs.xml file. Look for the key "iTunes Library Location:1".
    But I have a script that almost does what you want. Here is the perl source:
    http://home.comcast.net/~teridon73/itunesscripts/itunesopenlibrary.txt
    Here is a compiled EXE for it:
    http://home.comcast.net/~teridon73/itunesscripts/itunesopenlibrary.zip
    Anyway, the script basically works by setting the library location to a path that you pass to it. It does so by updating the iTunesPrefs.xml file. This file is very small, so you shouldn't need to worry about it!
    Of course, the script only works if the iTunesPrefs.xml file already exists. It would be nice if you could include a template iTunesPrefs.xml in your new user creation/login script. If the path is the same for every user, well, then you're done I guess.
    If not, you can run the script to set the path to what you really want it to be.
    Existing users are a different story. You can run my script to change the library location, of course. But then you also have to move their existing library file and their music back to that location. Well, you don't have to; you can make the users do it themselves! Also, I don't know if that will work as I haven't tested it.
    I haven't fully explained everything, but I don't have time right now. I hope at least I've given you some ideas. Of course the optimum solution is an Apple-provide GPO you could use. You can try asking apple for it via either a bugreport (if you have an ADC account), or the feedback page for iTunes:
    http://www.apple.com/feedback/itunesapp.html
    Rob

  • Question on Document Title in SOST

    Hi,
    Can some one let me know how Document Ttile comes into SOST.
    My scenario is;
    I am sending delivery note via email. my intention is to get document title as LD00 and Delivery Number (LD00 &LIKP-VBELN&
    below settings i tried but no use:
    Output type i am using is LD00.
    Configured Replacement of text symbols program as SAPMV50A & Form routine as TEXT_SYMBOL_REPLACE (even i tried with MAIL_TEXTS). Also In Mail title & Texts - i set my document title as LD00 &LIKP-VBELN&
    Hard coded text and passed to NAST-TDCOVTITLE in driver program but no use.
    After completing the process, i checked in SOST and i see different title (Program name, date, time).
    I put a break point in TEXT_SYMBOL_REPLACE routine and my cursor is not stopping in the routine. i tried in update debuggging also but not stopped in the routine.
    Pls let me know how can we stop in the routine or is there any other way to get custom document title.
    Thanks for your help!
    Regards,
    Sreeni

    I resolved my self

  • Scripting Bridge and Powerpoint, how to make new slide?

    I know how to make a new slide in an active presentation in Powerpoint. It works like this:
    tell application "Microsoft PowerPoint"
    set newSlideC to make new slide at before slide 2 of active presentation ¬
    with properties {layout:slide layout media clip and text}
    end tell
    (I stole this snippet from http://www.mactech.com/vba-transition-guide/index-094.html)
    Now I would like to do the same via Scripting Bridge in my Cocoa app.
    But I seem to be unable to find the appropriate classes, objects, methods, or properties in Powerpoint.h
    (which I created with this command:
    sdef /Applications/Microsoft\ Office\ 2008/Microsoft\ PowerPoint.app | sdp -fh --basename Powerpoint
    According to Script Editor's dictionary of Powerpoint, the "make" command is in the 'Standard Suite'.
    But I have no idea how to find it's defintion, let alone how to use it from my Cocoa application.
    Could somebody please give a hint to me?
    Since I'm not (yet) subscribed to the applescript-users mailing list, I am taking the liberty to post my question here.
    Thanks a lot in advance.
    Best regards,
    Gabriel.

    Hello
    You need to alloc and init to make an object instance in Scripting Bridge.
    See the following documents.
    Scripting Bridge Programming Guide for Cocoa
    http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ScriptingB ridgeConcepts/
    Scripting Bridge Framework Reference
    http://developer.apple.com/mac/library/documentation/ScriptingAutomation/Referen ce/ScriptingBridgeFramework/
    Some sample codes
    http://developer.apple.com/mac/library/samplecode/SBSendEmail/
    http://developer.apple.com/mac/library/samplecode/SBSetFinderComment/
    http://developer.apple.com/mac/library/samplecode/ScriptingBridgeFinder/
    http://developer.apple.com/mac/library/samplecode/ScriptingBridgeiCal
    As for your example, code would be something like this.
    NOT TESTED AT ALL. AND PROBABLY IT'S WRONG IN PARTS.
    Just for showing the outline, hopefully.
    PowerPointApplication *powerpoint = [SBApplication applicationWithBundleIdentifier:@"com.microsoft.powerpoint"];
    [powerpoint activate];
    PowerPointSlide *s = [[[powerpoint classForScriptingClass:@"slide"] alloc]
    initWithProperties:
    [NSDictionary dictionaryWithObjectsAndKeys:
    @"slideLayoutMediaClipAndText", @"layout",
    nil]];
    [[powerpoint.activePresentation slides] insertObject:s atArrangedObjectIndex:0];
    Good luck,
    H
    Message was edited by: Hiroto (fixed typo)

  • Scripting Bridge: how to set current iTunes playlist

    I know how to get the current iTunes playlist using Scripting Bridge, but how do I set the current playlist?

    This is the answer:
    1. Dig into iTunesApplication's "sources" to find iTunesSource "Library"
    2. Dig into iTunesSource "Library" to find iTunesPlaylist "Party Shuffle"
    3. Do a reveal.

  • How to get Safari to open an HTML document created in AIR on iOS

    We have an iOS app that creates a 3-page HTML document on the user's device and then prints it. We were using Darkredz ANE to do this, but the ANE is broken in iOS 8 and the Darkredz website is abandoned.
    As a workaround, we want to use Safari to launch the HTML document, then print from Safari. But Safari won't open a local document that belongs to another app, probably because of the security sandbox. We don't have a network connection, so we can't save the file remotely. Is there a way to get Safari to open a local document?
    If not, does anyone know of a FileManager app that can open files that are located in the "documents" folder of other apps on the device? I've tried several of them, but so far, they only load files from iCloud, Box, etc.
    Thanks for any tips.

    Sorry I didnt think about it needing to print as 3 separate pages at specific points. If you can't get the HTML printing to work then you could keep could this thought in mind. If the height of the, I presume, HTMLLoader object is the right value, you can draw the white-space of the page into the BitmapData and then it might still print at the right location. If it doesn't work immediately and you felt like putting in a little more effort, you might be able to tweak the height of the HTMLLoader objects so that each one represents a single page. Granted this approach would likely only work for one paper size format, such as 8.5x11. Sorry I don't have any easier ideas that work with what you already have done so far

  • JS scripted needed to add custom text plus filename to file info in document title

    Would greatly appreciate any help with this one...
    JS script to add custom text plus filename to file info in document title
    many thanks

    Super :O)
    I have a folder of say 50 images and I want to run a JS script batch
    example in the document title :  image Nr 81205
    custom text is "image Nr" +  file name "81205"
    activeDocument.info.title =" image Nr" + decodeURI(activeDocument.name);
    would this be correct without seening the file ext
    many thanks

  • Writing commands to get specific data channels in the output report via script or automated script generation..

    In my project I have to make certain calculation and then get the data plotted in the given report template. I am using automated script for this. My script is doing all the calculations and then it not selecting and drag-dropping the selected channels on the report template. Its saving the blank report template.
    I am struggling to get the data for specific channels plotted by using the script. I need the selected channels to be plotted on this report template and then get it saved.
    Any help will be deeply appreciated. Thanks
    Solved!
    Go to Solution.

    Hi LaxG,
    Brad is absolute right. It is possible to create your whole layout via script.
    If you have loaded  the example report layout you can copy these lines to create a new line in your plot. This is the recommended object oriented way.
    call Report.Sheets("Blatt 1").Objects("2D-Axis1").Curves2D.Add(e2DShapeLine, "anyName")
    Report.Sheets("Blatt 1").Objects("2D-Axis1").Curves2D.Item("anyName").Shape.XChannel.Reference               = "[1]/Zeit"
    Report.Sheets("Blatt 1").Objects("2D-Axis1").Curves2D.Item("anyName").Shape.YChannel.Reference               = "[1]/Geschwindigkeit"
    For performance reasons it's recommended to use the it like this.
    dim oLine
    set oLine = Report.Sheets("Blatt 1").Objects("2D-Axis1").Curves2D.Item("anyName").Shape
    oLine.XChannel.Reference               = "[1]/Zeit"
    oLine.YChannel.Reference               = "[1]/Geschwindigkeit"
    Like Brad mentioned it is much easier, that you have a stored template of your report with all setings and customisations already done.
    You open this layout file and have stored the names of your calculated channels. When you are doing this with a script they always have the same name and belong to the same group.
    Now you can customize the references of the line items.
    Kind Regards,
    Philipp K.
    AE | NI Germany

  • How to find a text in the Frame maker document via script?

    How to find a particular text in the Frame maker document via script?

    johnsyns wrote:
    Why it doesn't work for the other days? When i tried to change the days other than wednesday. it return nothing.
    Reason why Justin's code does not work for other days is date format mask DAY returns day blank padded to 9 characters which is the longest day name which, yes you guessed right, is WEDNESDAY. You either need to blank pad or use format modifier FM:
    SQL> select *
      2    from (SELECT TO_DATE(SYSDATE+ROWNUM, 'DD-MON-YY') dt
      3            FROM DUAL CONNECT BY ROWNUM <= 27)
      4  WHERE TO_CHAR(dt,'DAY') = 'TUESDAY'
      5  /
    no rows selected
    SQL> select *
      2    from (SELECT TO_DATE(SYSDATE+ROWNUM, 'DD-MON-YY') dt
      3            FROM DUAL CONNECT BY ROWNUM <= 27)
      4  WHERE TO_CHAR(dt,'DAY') = 'TUESDAY  '
      5  /
    DT
    07-APR-09
    14-APR-09
    21-APR-09
    28-APR-09
    SQL> select *
      2    from (SELECT TO_DATE(SYSDATE+ROWNUM, 'DD-MON-YY') dt
      3            FROM DUAL CONNECT BY ROWNUM <= 27)
      4  WHERE TO_CHAR(dt,'FMDAY') = 'TUESDAY'
      5  /
    DT
    07-APR-09
    14-APR-09
    21-APR-09
    28-APR-09
    SQL> SY.

  • Getting error: The document [document title was here] could not be saved."

    I am getting this error when trying to save a Numbers spreadsheet:
    "The document (document title was here) could not be saved."
    I created this spreadsheet from scratch in the numbers format, and I have been using it for several weeks now.
    When I 'get info' on the file and look at the file permissions, I see that my user has read and write access to the file. It is in the /Users/Shared directory as I share it with others on this computer. No other users are logged in, therefore the file is only open by me.
    I have already tried restarting the computer, and that didn't work.
    Any help would be greatly appreciated with this! I think others on this forum may have had a similar problem but they were blaming it on opening the file over a network. In my case as you can see, it is all local to my computer.

    Thanks for the suggestions. I tried all three and unfortunately the problems just got worse until the file would not open at all
    I had to restore from time machine from yesterday, then save as a different file. This allows me to edit the copy, but as soon as I try to edit it as a different use I go back to the same old problems again, even if the user has read & write permissions on the file and the directory the file is in.

  • How can I get iPhoto to display ONLY file numbers of pictures and not document titles when displayed as thumbnails?

    I am a pro photographer and I've never used iPhoto. I use a combination of Adobe's Bridge, Lightroom & Photoshop programmes.  I've sent a disk of images to a client and they cannot see the file numbers of the images.  Their version of iPhoto only displays the document title that I have embedded in the metadata when importing the images into Bridge.
    When I ran a test and imported the same images into my version of iPhoto(7.1.5, since you ask) some of the thumbnails displayed the file number while others displayed the document title.  Why does this happen?  Can I make it stop?  How do I make iPhoto display just the file number in thumbnail mode and not the document title?
    When I view the images in Bridge, all I see is the file number but I can't convince the client to use the programme even though they have it.  Any help/guidance will be very gratefuly received.
    Many thanks,
    Adam.

    In every version prior to iPhoto 11:
    Select one of the affected photos in the iPhoto Window and right click on it. From the resulting menu select 'Show File...
    In iPhoto 11:
    Select one of the affected photos in the iPhoto Window and go File -> Reveal in Finder -> Original...
    Regards
    TD

  • Get palette items via scripting

    Is it possible to access the control palette and its sub-palettes/controls within those sub-palettes via scripting? I'd like to get the strings of the available items
    CLA, LabVIEW Versions 2010-2013
    Solved!
    Go to Solution.

    so.....theres a read palette vi. Who woulda thought... SOLUTION!
    CLA, LabVIEW Versions 2010-2013

  • Get xml Document result via Toplink.

    Hi.
    I want to get XML Document result instead of the entities of the table by using the Toplink.
    Who have some advices?
    Thanks.

    Please try the toplink forum.

Maybe you are looking for

  • Regd: Calculation of TOTAL field in ALV report

    Hi All, We have a scenario that we are not getting the total value for numeric fields in ALV report. Below i have given the code used for it. G_KEY = 'X'.   G_NOKEY = SPACE.   G_SUM = 'X'.   G_NOSUM = SPACE.   PERFORM BUILD_FIELDCAT USING 'VBELN'  G_

  • Different colors for the aggregation in the report

    Hi In my BEx report I require to show the aggregation in different colors. That is suppose my report has 3 characteristics and 2 keyfigures. When the 'Result' appears for characteristic1 it should be shown in blue color(not specific) and when the res

  • Stored procedures (SQL 7 to Oracle 8i)

    Using latest OMWB, all our stored procedures are coverted to Oracle as procedures. Some should convert as functions because we retuen an integer value in SQL 7. The migration options are set to automatic generation of procedure or function. What is i

  • Http response code 403

    hi all.... I'm trying to work on the file-xi-file scenario...everything is working fine but it is not showing the file in the destination directory... when i checked the RWB...it says.... Transmitting the message to endpoint http://SAPXI:8000/sap/xi/

  • Can't open domain file

    I was saving my iWeb project, when the application suddenly shut down unexpectedly. Now when I try to restart iWeb, it says it can't open my Domain file. I can see the Domain file, right where it's supposed to be, I just can't get iWeb to open it up.