AppleScript: search clipboard text on sixhat.net

AppleScript: search clipboard text

When I’m working on something interesting I usually want to check if I’ve already mentioned it the blog. This script allows me to quickly open a new tab on Google Chrome and search on sixhat.net for a text that I’ve copied into the clipboard.

-- This script is based on a script of Computer World
-- http://goo.gl/CZgIw0
 
set url1 to "https://www.google.pt/#q=site:sixhat.net+"
 
tell application "System Events"
	set myquery to the clipboard
end tell
 
-- changes space to plus using function at end of file
set thequery to SaR(myquery, " ", "+")
 
tell application "Google Chrome"
	activate
	set theURL to url1 & thequery
	open location theURL
end tell
 
on SaR(sourceText, findText, replaceText)
	set {atid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, findText}
	set tempText to text items of sourceText
	set AppleScript's text item delimiters to replaceText
	set sourceText to tempText as string
	set AppleScript's text item delimiters to atid
	return sourceText
end SaR

You can easily adapt the script for your own use by changing the variable url1 in the conde. If you prefer to use Safari instead of Google Chrome that is also easy to change in the code above.

To use the script you can use the Script Editor (AppleScript Editor in previous versions of OS X) and then save the script in your User Scripts folder (~/Library/Scripts). If you prefer you can also download the applescript and the edit from there.

Force macports to upgrade all outdated ports

if you are a macports user you probably upgrade the ports you have in your machine with the command

port upgrade outdated

but sometimes some packages gets broken and can not be installed, leaving other macports packages that could be upgraded stuck at old versions. The only solution is to manually upgrade each one of them with port upgrade. The way I force the upgrade of all macports packages is just to list all outdated packages and then try to upgrade one by one with:

for l in `port outdated | awk '{print $1}'`  
do  
port upgrade $l  
done

this doesn’t stop packages from failing, but at least allows you to upgrade all macport packages that can be upgraded. The process will take time, and is a bit crude because it doesn’t take into consideration things like dependencies, but works and in the end I’ve found that sometimes it even solves some of the problems of broken packages. Give it a try.

Extra: After successful upgrades—and only if you don’t need the old versions that are still installed but not activated—you can just uninstall the unactivated macports with

port uninstall inactive

(All commands should be issued under superuser permissions either with sudo prefixed or using sudo -i)

Search better than apple’s spotlight

EasyFind

I hate that spotlight indexes external drives. I hate waiting for hours for it to create hidden folders of catalogs that are just waisting space. I hate that it does it to my friends drives that I will only use once and that they will take home with a strange index folder full of rubbish.

So I disable external drive spotlight indexing but now HOW AM I GOING TO SEARCH IN THOSE VOLUMES?

Well, there are Unix ways of doing the search, but I’m don’t spend 100% of my time on a Terminal window.

ENTER EasyFind from the DEVONThink guys.

A NO INDEX search software for MAC that acts perfectly to search files, folders, content in files, etc… A life saver on the toolbox of any Mac Computer.

No more spotlight rubbish please!

Mac Mini Late 2012 Teardown

The latest Mac Mini Late 2012 Teardown from iFixit shows that the Mini is easily RAM upgradable and HD upgradable. This makes it a good contender for my next home machine. Don’t understand why apple insists in shipping their machines with only 4GB of RAM. It is clearly short for Mountain Lion.

Notas sobre o upgrade para Mountain Lion

No fim de semana decidi fazer upgrade ao meu MacBook Pro que estava a correr ainda o OSX 10.5.8 Leopard (principalmente por questões de compatibilidade com algumas bibliotecas que preciso e cujo upgrade iria obrigar a mudar imenso código, e obrigou).

Bem, este fim de semana foi o dia (muitas vezes adiado) de fazer upgrade para o Mountain Lion. Ao fim de alguns dias de utilização eis algumas conclusões:

  • Instalação do Mountain Lion crashou! A única forma de o instalar foi fazendo um clean install e mesmo assim o tempo que Apple estima que a instalação demora é tão preciso como nos melhores dias da Microsoft no Win95 a instalar a partir de disquetes (umas 30). Tendo durante muito tempo o processo de instalação mais friendly do mundo, é pena ver estes “falhanços” do instalador. O prémio para o OS mais fácil de instalar do mundo regressa novamente para o Ubuntu.

  • Com 4GB de RAM o Mountain Lion arrasta-se num Macbook Pro de finais de 2008. O problema é o consumo de memória. Por algum motivo ao Mt. Lion não gosta de libertar memória inactiva e prefere fazer swap para disco.

  • Na segunda feira tive que fazer upgrade para 8GB de RAM e a verdade é que para já o problema está resolvido (embora já tenha esgotado 2 vezes a RAM – Sou um bruto eu sei, utilizo computadores para os por a trabalhar a 100%).

  • A primeira vez que o Time Machine correu teve que gravar 200GB de dados. Não sei porque motivo, mas o daemon do time machine ocupou quase 3GB de RAM (assim não há ram que aguente).

  • Ainda não percebi que fatures novas do Mt. Lion vão alterar a minha utilização de computadores. O Bling extra por si é dispensável se não for também reflexo de usos mais fáceis. Para já continuo a utilizar as mesmas ferramentas e rotinas de sempre e não é por ter já cabelos brancos. É porque simplesmente muitas das features novas não são realmente novas e já existiam noutros OSes, e já nesses OSes não eram utilizadas porque havia formas mais rápidas e eficientes de ser produtivo.

  • Uma das coisas que acontece aos meus OSes ao fim anos de utilização intensiva é que acabo por ter muita duplicação de software no disco. Decidi começar a limpar. Software cuja funcionalidade já exista no OS sai. As primeiras vítimas foram o Thunderbird, o Firefox, o Opera e o Chrome. Próximo round são os editores de texto (Textmate, Wrangler, BBedit, MacVim, Smultron, etc… ) Só um ficará, para já inclino-me para o Textmate ou para o Wrangler ou Vim… ai.. decisões.

  • Os tempos de vida dos Mac são verdadeiramente longos. Se no passado a Apple suportava máquinas com 5,6…8 anos, agora tal já não é verdade, mas um MBP com 4 anos e com um ligeiro upgrade está ainda a funcionar para mais um par de anos. Eventualmente precisará de um disco SSD, mas não é obrigatório. No entanto a idade reflecte-se noutras coisas: bateria morta a precisar de substituição, ventoinhas ruidosas, etc.

  • Trazendo aqui ao barulho o iOS6 recentemente lançado, fico com a sensação que nem o iOS6, nem o Mountain Lion veriam a luz do dia no tempo do Steve Jobs. As razões são subtis mas estão lá nas pequenas falhas e imprecisões destes dois produtos. Espero estar enganado.

AppleScript: How to skip 30/rewind 10 seconds in iTunes?

With the launch of Podcasts for the iOS devices, Apple introduced two buttons on the device to skip 30 seconds (great for skipping advertisements, or Sarah Lane segments in Tech News Today) and to rewind 10 seconds for quick replay of something important that you missed.

Well, iTunes is my desktop app for podcast subscription and management and unfortunately these two buttons don’t exist in iTunes. For this I use two applescripts that I’ve labeled iTunes-Skip-30 and iTunes-Back-10. They sit in my scripts folder and any time I want to use them I just access the scripts from the top menu bar.

-- iTunes Skip 30
tell application "iTunes" to set player position to (player position + 30)
 
-- iTunes Back 10
tell application "iTunes" to set player position to (player position - 10)

You just need to use your Script Editor and save each of these scripts in your user scripts folder (usually in ~/Library/scripts/) and enable the scrips menu in the Scripts Utility.

AppleScript: Word Count, anywhere

Sometimes one needs to count the number of words and characters of text that we’ve written.

Here’s a small script to do just that:

set nChars to count (the clipboard)
set nWords to count words of (the clipboard)
 
display dialog "Characters: " & nChars & "
Words: " & nWords

Use Script Editor and paste the above code. Then save it to your scripts folder and every time you want to have word count just copy the text and invoke the script.