Wednesday, March 10, 2010

rescue off-screen windows with applescript

i work with dual screens a lot on my macbook specially when i’m at home. every once in a while i would be in too much of a hurry to remove my vga display adapter or return windows to the main screen before putting my macbook to sleep. as a result, i have some windows that are off-screen when my macbook wakes up.

it happened to me again this morning so i finally decided to do something about it. i asked my friend google to see if there was a quick solution i could use. turns out it’s a pretty common occurrence and this mac rumors thread i found had some possible solutions:

  • use Windows -> Zoom
    • doesn’t work if the application did not implement this like keepass and opera (my problem window)
  • gather windows button
    • this only appears when you have a second display attached. if that were the case, i wouldn’t be having this problem in the first place :)
  • spaces + expose
    • doesn’t really work. even if you are able to drag the preview window from one space to another, once you revert to the normal view the window returns off screen only this time in the current space you dragged it into.
so no solutions so far, at least none that worked for me.

fortunately, at end of the same thread someone wrote that it was possible to do it using applescript. he had actually posted some script but he mentioned that running the script had some sort of side effect that could be only be cleared by a reboot. i rarely reboot my macbook so this was not an option for me but it did get me thinking that i could probably write a quick script that would solve my problem. it won’t be a generic solution but it will be a quick an easy solution.

after a bit of research i was able to write a very short applescript that solved the problem and here it is:
tell application "Opera"
activate
set the bounds of the first window to {100, 100, 500, 500}
end tell
it doesn’t really matter what the bounds were as long as they were within the main screen. after running the script my opera window was finally on-screen and all that was left to do was resize the window. problem solved :)

Labels:

Monday, November 02, 2009

can't type in firefox

i've been using firefox for a while now, since firefox 2.x if i remember correctly, and i've been very happy with it. in fact, it has been my browser of choice for years be it for linux, windows, or mac. i even had portable firefox ready in one of my thumb drives just in case i'm on some machine without firefox installed. sadly, i can't say the same for version 3.5. so much so that google chrome is now starting to spend more time on my dock.

being a user of bleeding edge open source software for sometime now, i'm used to playing around with buggy apps. when something goes awry i know that solving it usually just involves at least one of 3 r's: restart, reboot (usually with windows), or reinstall. but for software like firefox which is now on 3.5, this shouldn't have to be the case. unlike beta or alpha software of which i am more forgiving, i expect much more from a product of this level of maturity. were not talking 1.0 here, it's version freakin' 3.5 already!

anyways, enough of my firefox rant let me get to the actual point of this post!

since 3.5 (at least that's when i started noticing it) my firefox, after running smoothly (more or less) for some hours would occasionally stop working. to be more specific, it would just suddenly stop receiving input from my keyboard. i could close tabs just fine, but i couldn't type on any text field! not on any text field in the current page i'm on nor the url or search fields of the actual browser. in the past, i would just shutdown firefox (kill/force quit mostly since it more often than not stops responding as well), but today i just got fed up and started looking for a solution. also, i didn't want to kill firefox because there were some tabs that i haven't bookmarked yet.

determined not to let this get the better of me, i turned to our friend google for a solution to my problem. with google chrome and a bit of google-fu, i got these results using the following keywords: firefox can't type. the first page of the search results alone told me that i was not alone. there were actually 24,200,00 results and although this is not necessarily an indicator of how prevalent the problem is, the results on the first page sure are. with results such as these, i was confident that the solution was just a click or two away.

the first result was actually all i needed. a very helpful post from pengunassasin said:

i wasn't actually running greasemonkey, but this post was a very good hint at the problem: javascript.

i'm not sure if it's the web programmer's fault for using window.stop() or the firefox (or firefox add on) developers fault for mishandling the interpretation of the code but i think both of them are at fault. the web programmer for not knowing better, and the firefox developers for not handling it properly. i mean, firefox developers, why would you allow an arbitrary piece of javascript code to stop the whole browser from receiving input? even if you say that window.stop() shouldn't really be used, it's there so you should be prepared to handle it!

dang, went into another rant there.

so what is the solution, very simple actually, just disable and then re-enable javascript in preferences. easy.

for those not familiar with how to do that here's a screen cap:

hope this post helps someone out there.

oh and one more thing... woohoo! another blog post after almost a year! well at least, it wasn't 2 years like the last time =)

Labels: , ,

Thursday, November 13, 2008

Trash on Leopard Stopped Working

don't you just hate it when you can't empty your trash bin on your mac? happens to me all the time, i trash some locked file (or something) and the next thing you know, empty trash no longer works, at least not for that file. it's not really a problem, just annoying. i mean sure the next time i restart my mac my trash bin would be empty but how often do you restart your mac? if you're like me, probably only after a software update that requires a restart =) and in the meantime the trash bin looks like it's full of trash, it just really gets on my nerves after a while. so here's what i did to solve that little annoyance:
  1. launch terminal
  2. make sure you are at your home directory. do a pwd just to be sure
  3. execute: rm -rf .Trash
  4. execute: mkdir -m07000 .Trash
and voila! my trash was now empty. there was just one little problem... my Trash bin stopped working altogether! now, whenever i did a move to trash using finder it just said that it was going to be deleted permanently. not good... so how did i solve this problem? it was simple really, Finder was able to detect that the .Trash folder had been deleted, unfortunately, it could not detect that the .Trash folder was recreated. a simple restart of Finder did the trick. you can do that by either:
  1. doing a force quit:
    1. press command + alt + esc
    2. select Finder
    3. click Relaunch
    4. click Yes to force quit

  2. doing a kill using the console:
    1. launch Terminal
    2. execute: killall Finder
    3. relaunch Finder using your Dock icon
was this really the best way to solve the trash problem? well, it would have been better if i didn't delete the .Trash folder. besides, the problem was with the contents of the trash bin not the actual trash bin. below would be the better way of doing it:
  1. launch terminal
  2. make sure you are at your home directory. do a pwd just to be sure
  3. execute: rm -rf .Trash/*
well, you know what they say... learn by doing :)

Labels: ,