AppleScript help - global window data gatherer

Posted:
in Genius Bar edited January 2014
So I've had this idea kicking around for a while, and want to finally move forward on it.



Workspaces.



I already have virtual desktops going, and want to take it a step further.



I'd like to have a script that I can run that will query all running apps, and ask them for their list of windows. For each window, it will query the position and size, and the document info. For each document, it will find the file on disk, and make an alias to it in a folder.



Another script will go to that folder, select all, and open via the Finder.



Voila. Need to restart? Run the first script, reboot, run the second, and you're right back where you were. You can keep project folders independent of the storage. For instance, right now I have a massive project (my dissertation) that I'm constantly working on different parts of as subtasks. I could have subtask folders that slice across the rather large storage folders and pick out just the files I need for a specific job until its done, and then I can trash that subtask folder.



So I figure AS is good for this... but I haven't touched AS in months, if not years. Anyone want to give me a hand with it? Anything that comes of it will be posted here for everyone to use.

Comments

  • Reply 1 of 9
    neutrino23neutrino23 Posts: 1,563member
    It depends on what applications you want to use. Some like Tex-Edit Plus and Adobe InDesign are very scriptable and could do what you ask easily. Many others are not scriptable at all.



    Open the script editor (on your disk) and then use that to open the AppleScript dictionary for every application you use.



    Most applications that are scriptable at all will let you count the open windows and get their positions.
  • Reply 2 of 9
    kickahakickaha Posts: 8,760member
    Agreed - I envision this just working through the standard suites for those apps that support it, and ignoring those that don't.



    What I have so far is irritatingly close:



    Code:


    on run

    set docs to {}

    getdocs from "SubEthaEdit"

    makealiases(docs)

    end run



    on makealiases(docs)

    tell application "Finder"

    set wsref to folder "/Users/smithja/Library/Application Support/Workspaces" -- ERROR

    repeat with doc in docs

    make new alias file at folder "/Users/smithja" of startup disk to doc

    end repeat

    end tell

    end makealiases



    on getdocs from theApp

    tell application "SubEthaEdit"

    set winds to windows

    repeat with wind in winds

    set doc to (path of (text document of wind))

    set my docs to my docs & doc

    end repeat

    end tell

    end getdocs







    The noted line returns "Finder got an error: Can't get folder "/Users/smithja/Library/Application Support/Workspaces"." This path vs. reference thing is really annoying. :P
  • Reply 3 of 9
    neutrino23neutrino23 Posts: 1,563member
    Not sure about the rest of it but you can clean up that one line by changing it to



    set wsref to folder "workspaces" of folder "Application Support" of folder "Library" of folder "smithja" of folder "Users"



    It seems awkward and there may be another way but this works format works.



    Two lines down you'll need a similar change.
  • Reply 4 of 9
    kickahakickaha Posts: 8,760member
    Oddly, that's how I originally had it, and it gave me the same error.
  • Reply 5 of 9
    torifiletorifile Posts: 4,024member
    Who said the only way you've got left to procrastinate is to post here?
  • Reply 6 of 9
    neutrino23neutrino23 Posts: 1,563member
    Do you have FileVault turned on? If so you can't access anything in your home directory as you normally would.
  • Reply 7 of 9
    defiantdefiant Posts: 4,876member
    Hmm? interesting. Might look into this, but you have to promise me that you'll return to this thread, unlike some other mod fellow who doesn't return to his own thread, even though we tried to help him
  • Reply 8 of 9
    kickahakickaha Posts: 8,760member
    No, no FileVault.



    I also was unable to create a folder in /tmp/501/, which surprised me. Permissions looked correct. I'm wondering if the fact I'm running it from within Script Editor is the problem.
  • Reply 9 of 9
    defiantdefiant Posts: 4,876member
    Script editor can be a bitch sometimes.

    Maybe, if you feel like creating a whole app, which is not that difficult, you coud do it with AppleScript Studio. You can 'invoke' ASS when you start Xcode.



Sign In or Register to comment.