Thursday, July 23, 2015

Setting up Wireless Access Point using Apple's Airport Express

I'm using ADSL internet connection at my home, in which there is a cable from ISP connected directly into my modem. I want to set up a wifi network from it. The only thing I need is Airport Express. I just plugged in the ethernet cable from the modem to the Airport Express and configure it as following:

1. Connecting modem to Airport Express



2. Configuring the Airport Express from MacBook/iPhone/iPad by using Airport Utility application. The application come with Mac OS X by default. You need to download and install the app for iPhone and iPad. The steps below show how to configure it.
















Friday, July 10, 2015

Mac OS X: Put your machine to sleep automatically when low battery

I don't want my machine shutdown because of out of battery because I may get the issues such as losing unsaved tasks and my hard drive is not mounted when the machine starts again. The Energy Saver settings in Mac OS X can put my machine to sleep after it has been idled for a period of time but it can't help in my case because most of the time I leave the music player app running so my machine is never idle.

Thus, I created an AppleScript that automatically put my machine to sleep when the battery is lower than %15. The script will be executed every 3 minutes by a cron job. For info, I'm using Mac OS X Mountain Lion 10.8.

1. Create the Apple script


Open AppleScript Editor and insert the following code and save it as SleepWhenLowBattery.scpt in /Applications/MyApps/ directory.

property lowBattery : 15

set battStatus to do shell script "pmset -g ps"
if battStatus contains "Battery Power" then
 set {TID, text item delimiters} to {text item delimiters, ";"}
 set battStatus to text items of battStatus
 set text item delimiters to tab
 set battStatus to text 1 thru -2 of last text item of item 1 of battStatus as integer
 set text item delimiters to TID
 
 if battStatus < lowBattery then
  tell application "Finder"
   activate
   set alertResult to display alert ¬
    "Low battery! Your machine is going to sleep in 90 seconds..." buttons {"Cancel", "Sleep Now"} as warning ¬
    default button ¬
    "Cancel" cancel button ¬
    "Cancel" giving up after 90
   
   
   if gave up of alertResult then
    do shell script "pmset sleepnow"
   else if button returned of alertResult is "Sleep Now" then
    do shell script "pmset sleepnow"
   end if
   
  end tell
 end if
end if
return 60

This script checks the current battery status. If it's lower than the defined value, it displays an alert saying that the machine is going to sleep in 90 seconds and the user can choose to sleep now or cancel.

Below is the sample output of the command 'pmset -g ps'  while charging:
$ pmset -g ps
Currently drawing from 'AC Power'
 -InternalBattery-0 60%; charging; (no estimate)
Below is the sample output of the command 'pmset -g ps'  while discharging:
$ pmset -g ps
Currently drawing from 'Battery Power'
 -InternalBattery-0 61%; discharging; (no estimate)
So, the script will put your computer into sleep only if your machine is not charging.


Another note about the script is that the code to display the alert need to be put in 'tell application "finder"' block or you'll get the error message below logged by the cron job in /var/mail/${username} file. Without that block, the script can still be executed manually by the user from Terminal.
/Applications/MyApps/SleepWhenLowBattery.scpt: execution error: No user interaction allowed. (-1713)

2. Create a cron job to run the script every 3 minutes


Open Terminal and type:
crontab -e
It will open crontab configuration file in VI editor. And then press 'I' key to be able to write into the file and insert the following line.
*/3 * * * * osascript /Applications/MyApps/SleepWhenLowBattery.scpt 
After that, press 'Esc' key and type ':wq' to save change and quit the VI editor. Please note that the cron job running interval should be greater than the waiting time before machine sleeps (90 seconds) defined in the script above or you will get more than one alerts on your screen if you don't close them. This cron job does not run for all users; it's for the current user only.

Now, you're done; you DON'T need to restart your machine or logout.






References
https://discussions.apple.com/thread/3836771
http://stackoverflow.com/questions/13484482/no-user-interaction-allowed-when-running-applescript-in-python

Saturday, July 4, 2015

Mac OS X: Applications do not remember their desktops or spaces

I'm using Mac OS X Mountain Lion 10.8. I have a few desktops to group applications. But, sometimes the applications start in wrong desktops or spaces. They do not remember their desktops. It's the default behavior of Mission Control. You can change it as following:

1. Open System Preferences
2. Click Mission Control
3. Uncheck Automatically rearrange spaces based on most recent use


Saturday, May 9, 2015

Chrome Issue: We are having trouble playing this video.

I was using Chromium browser v37 on Mac OSX Lion v10.7 and I was able to play videos on any sites such as Youtube, Facebook, and so on. After I upgraded it to v44, I still could play videos on Youtube but not on Facebook and it showed the message below.


To fix the problems,
1). Type "chrome://flags/#enable-npapi" in browser's address bar
2). Find the item "Enable NPAPI Mac, Windows" and click on Enable link
3). Restart browser






References

https://www.facebook.com/help/community/question/?id=10202758465869794 - commented by Gary Miller.
https://www.java.com/en/download/faq/chrome.xml#npapichrome



Chrome Issue: Adobe Flash Player needs your permission to run

I was using Chromium browser version 37 on Mac OSX Lion v10.7. Then, I upgraded it to version 44. After the upgrade, I could play videos on Youtube but not on Facebook. It said: "Adobe Flash Player needs your permission to run" as in the below screenshot.


To solve this problem:
1). Type "chrome://plugins/" in the browser's address bar
2). Find the item "Adobe Flash Player - Version: xxx" and check "Always allowed to run" checkbox. Note that if we don't enable NPAPI, we might not see the item in the plugins list. To enable NPAPI, see http://myt8chnote.blogspot.com/2015/05/chrome-issue-we-are-having-trouble.html
3). Restart browser




Friday, April 17, 2015

Missing embedded player when sharing Youtube video on Facebook

When I shared a youtube URL, there is thumbnail image instead of an embedded player. Hence, every time you click on the thumbnail, you're redirected to youtube website. You can't play it directly on Facebook. The URL shared might look like following:


What I want it to be is:


The reason is the video owner disabled embedding. We can't do anything about that if we're not the owner. You can see whether the embedding is enabled or not by clicking on the Share icon then Embed and you'll see as in the image below if embedding is disabled.


If embedding is enabled, you'll see as following:


You might have to look for another video that embedding is enabled.


Monday, March 30, 2015

Failed to open or import Maven project in IntelliJ IDEA

I'm using IntelliJ IDEA 14 on Mac OSX Lion and I hadn't had any problems with opening or importing Maven projects before I updated Java from 1.6 to 1.8. The IDE started successfully but every time I opened or imported an existing Maven project, a popup appeared to display the progress of opening or importing process for a short time but after that nothing happened. Then, I opened the Console application and I see the log message below:
3/31/15 1:05:18.637 AM [0x0-0x8d38d3].com.jetbrains.intellij.ce:   Referenced from: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java
3/31/15 1:05:18.637 AM [0x0-0x8d38d3].com.jetbrains.intellij.ce:   Reason: image not found
It means that IDEA was still using JDK 1.6 and it no longer existed on my machine after the update. I solved the problem by telling it to use the JDK 1.8 instead when starting and building projects. To do it, I did as followings:

1). Open the IDEA's configuration file:
open -e /Applications/IntelliJ\ IDEA\ 14\ CE.app/Contents/Info.plist 

2). Update the following key
<key>JVMVersion</key>
<string>1.7+</string>
I have both JDK 1.7 and 1.8 on my machine.

3). Restart the IDE



Reference

https://devnet.jetbrains.com/docs/DOC-197