Archive

Archive for the ‘Applescript’ Category

Run Applescript on new email

July 26th, 2011 No comments

I’m still experimenting, but so far I found two strategies:

  • Enable Folder Actions and attach a script to the folder in ~/Library/Mail/ which hold the inbox’s messages
  • Create a rule general enough to reply to all messages (e.g. account = my_email_account)

The rule approach seems to fire a bit quicker than the Folder Actions, so I’m going with that for the moment.

Categories: Applescript, Mac Tags:

Love poor technology for simple tasks

April 25th, 2011 No comments
I Have a Dream

If I had my way, I would never leave my Smalltalk image.

It’s not just the Smalltalk language (although I do enjoy the Zen-like minimal syntax, and keyword arguments flow off the keyboard like conversational speech). The real gold is the live, open environment, and control over everything in my system, almost down to the metal.

Reality Sets In (but it’s not so bad this time)

Yet sometimes, for a quick and dirty throwaway script, a tool symbolizing poor design is perfect.

For example, I wanted to change the artist info of a batch of tracks in iTunes. In less? time than it would have taken me to google a solution, I had whipped up an AppleScript (yes, ouch) in AppleScript Editor (double ouch):

tell application "iTunes"
	set wrongName to ""
	set rightName to ""
	set track_list to tracks of playlist "Music" of source "Library" whose artist is wrongName
	repeat with t in track_list
		set artist of t to rightName
	end repeat
end tell

Yes, I could have used rb-appscript to script from Ruby, which I usually do. But, AE gave me easy access to iTunes’ scripting dictionary, a nice little “Run” button, and an output pane. For this tiny script, I was done before I started to suffocate from being outside the oxygen of my live, open Smalltalk image.

So, thank you Apple, for creating the infuriating AppleScript language, to be written with the puny AppleScript Editor, and for not even making many of your own applications scriptable ([cough] Preview.app) even while evangelizing scriptability to Mac devs in your docs. Today, I was grateful for it all. Editing info on hundreds of tracks was much quicker than writing this post about it :)

Categories: Applescript, Programming, Ruby, Smalltalk Tags:

Applescript to change genres in iTunes

May 12th, 2010 No comments

There is this awesome programming language in which the entire system (down to the graphics libraries, window system, and compiler) is available to you to reinvent, opening the possibility of truly open computing.

Obviously, I’m talking about Smalltalk. But if you are too afraid to give MS and Apple the bird for not learning (or wanting to learn?) the computing lessons of the 1970′s, there is another option which lets you bend almost any Mac application to your will, breaking it from the chains of presumptuous software giants who think you should work the way they design instead of vice versa.

I’m speaking, of course, of Ruby, lol. If you’re doing any serious Applescript development, ditch Applescript altogether, and check out the rb-appscript library.  It allows you to do anything you can do in Applescript, in a non-ambiguous way, with the power of a full programming language behind you – trust me, it’s the heaven where Applescript will go when it finally dies.

However, if you’re doing something simple and common, especially in a very scriptable application like iTunes, sometimes it’s easier to just crank up AppleScript Editor and hack out a one-liner.

Thus this very simple script to change the genres of iTunes tracks, which I used to fix things like some tracks in the “rock” genre and others in the “Rock” genre.

tell application "iTunes"
  set tracks_to_fix to file tracks of playlist "Music" of source "Library" whose genre ends with "ock"
  set genre of tracks_to_fix to "Rock"
end tell

Applescripting Xcode

November 11th, 2009 2 comments

Have you wanted to automate your Xcode workflow, but couldn’t figure out exactly how to work the AppleScript commands? Well, here’s a whole object-oriented library of handlers for ya!

(Sorry I haven’t figured out a better way to format AppleScript code in a blog; any ideas, please let me know)

on target_object(the_target)
    script target_obj
        property target_ref : ""

        to add_source_file(the_file)
            tell application "Xcode"
                add the_file to (get compile sources phase of target_ref)
            end tell
        end add_source_file

        on set_header_search_paths_for_all_configurations(the_path)
            tell application "Xcode"
                (* configuration is Debug or Release *)
                set value of build setting "HEADER_SEARCH_PATHS" of build configurations of target_ref to the_path
            end tell
        end set_header_search_paths_for_all_configurations

        to add_run_script_phase(the_name, the_script)
            tell application "Xcode"
                tell target_ref
                    return make new run script phase with properties {name:the_name, shell path:"/bin/sh", shell script:the_script}
                end tell
            end tell
        end add_run_script_phase
    end script

    tell application "Xcode"
        set target_obj's target_ref to the_target
    end tell
    return target_obj
end target_object

on group_object(the_group)
    script group_obj
        property group_ref : ""

        to add_file(the_path, the_file_name)
            tell application "Xcode"
                tell group_ref
                    return make new file reference with properties {full path:the_path, name:the_file_name}
                end tell
            end tell
        end add_file

    end script
    set group_obj's group_ref to the_group
    return group_obj
end group_object

on active_project()
    script project_obj
        property project_ref : ""

        to add_group(group_name)
            tell application "Xcode"
                tell project_ref
                    -- Get project directory
                    set project_dir to project directory

                    -- Create new folder for group's files
                    tell application "Finder"
                        set file_lib to load script alias "Macintosh HD:Users:sean:Library:Scripts:My Library:Files.scpt"
                        make new folder at (file_lib's posix_string_to_hfs_file(project_dir)) with properties {name:group_name}
                    end tell

                    -- Create new group
                    tell root group
                        return my group_object(make new group with properties {name:group_name, path type:project relative, path:group_name} at beginning)
                    end tell
                end tell
            end tell
        end add_group

        to make_new_shell_tool_target(target_name)
            tell application "Xcode"
                tell project_ref
                    set unit_test_template to target template "BSD/Shell Tool"
                    return my target_object(make new target at end of targets with data unit_test_template with properties {name:target_name})
                end tell
            end tell
        end make_new_shell_tool_target
    end script

    tell application "Xcode"
        set project_obj's project_ref to project of active project document
    end tell
    return project_obj
end active_project

You can also download the scpt file here.

And here’s a script that uses the handlers.

Categories: Applescript, Xcode Tags: ,

Undo last action in PersonalBrain

November 9th, 2009 No comments

Until now, undoing your last action in PersonalBrain has been annoying – there is no shortcut, so you had to choose undo from the menu.

Here’s a short Applescript that does it for you:

activate application “PersonalBrain”

tell application “System Events”

tell process “PersonalBrain”

try

– See if there is a list of undos

get value of attribute “AXChildren” of menu item “Undo” of menu 1 of menu bar item “Edit” of menu bar 1

– If there is, undo the most recent

click menu item 1 of menu 1 of menu item “Undo” of menu 1 of menu bar item “Edit” of menu bar 1

on error

– There are no children, so click Undo

click menu item 1 of menu 1 of menu bar item “Edit” of menu bar 1

end try

end tell

end tell

Assign a shortcut to the above script and… you have vanilla undo… yay!

Categories: Applescript Tags:

Quickbooks for Mac 2010 Time Activity Bug

October 28th, 2009 No comments

I’ve run into a bug which is discussed here.  In summary, after entering a single time activity, hitting “next” or “previous” causes problems.

With the following Applescript, when you’re finished entering a time activity, you hit ctrl+n (or whatever shortcut you choose), and voilà:

  • you have a saved entry
  • a new blank form
  • you can scroll to previous and next to your heart’s content!

That is – it works the way it’s supposed to, lol

Here’s the code:

tell application “System Events”

tell process “QuickBooks 2010″

click button “OK” of window “Enter Single Activity”

perform action “AXPress” of menu item “Enter Single Activity” of menu 1 of menu item “Time Tracking” of menu 1 of menu bar item “Employees” of menu bar 1

end tell

end tell

Here’s what you do:

  1. Paste the above script into AppleScript Editor
  2. Save the file (as a script) to: /[your user folder here]/Library/Scripts/Applications/QuickBooks/Save time activity and create new.scpt
  3. If you have an script menu app (FastScripts is the absolute best!), you can assign a shortcut to it, like ctrl+n)
Categories: Applescript Tags: , , ,

Applescript to safely open links from Apple Mail

July 27th, 2009 No comments

I’m (justifiably) nervous about following links from emails.  I wrote an applescript that sets my mind at ease.  It works like this:

  1. I copy the link to the clipboard (right-click on it)
  2. I run the script
  3. it automatically finds the site name e.g. “orbitz” from “orbitz.com” and opens up a new google search in Safari.
  4. When I click on the hit that’s the real site, the script inserts the domain name of the real site into the link from the email
  5. The valid link comes up in Safari

I just thought about searching my Safari bookmarks, but this got the process down from manually editing the URL to three mouse clicks, so I’m happy :)


set link_to_scrub to (get the clipboard)

set text item delimiters to "/"
set tokens_to_scrub to text items of link_to_scrub

set domain_name_to_scrub to (get item 3 of tokens_to_scrub)

set text item delimiters to "."
set url_labels_to_scrub to text items of domain_name_to_scrub

tell application "Safari"
activate
make new document with properties {URL:"http://www.google.com/search?q=" & (item 2 of url_labels_to_scrub)}

set current_url to a reference to URL of document 1

repeat until current_url starts with "http://www.google.com/"
delay 0.1
end repeat

repeat while current_url starts with "http://www.google.com/"
delay 0.1
end repeat
end tell

set text item delimiters to "/"
set real_tokens to text items of (current_url as string)

set real_domain_name to (get item 3 of real_tokens)

set text item delimiters to "."
set real_url_labels to text items of real_domain_name

repeat with current_label_index from -2 to -1
set item current_label_index of url_labels_to_scrub to item current_label_index of real_url_labels
end repeat

set real_domain_name to url_labels_to_scrub as string
set item 3 of tokens_to_scrub to real_domain_name

set text item delimiters to "/"
set real_link to (tokens_to_scrub as string)

tell application "Safari"
activate
set URL of document 1 to real_link
end tell

Categories: Applescript, Mac Tags: , , ,

windows 7 product key

windows 7 product key

windows 7 key generator

windows 7 key generator

free winrar download

free winrar download

winzip activation code

winzip activation code

free winrar

free winrar

winzip free download

winzip free download

winrar free download

winrar free download

winrar download free

winrar download free

winzip free download full version

winzip free download full version

windows 7 activation crack

windows7 activation crack

windows 7 crack

windows 7 crack

free winzip

free winzip
\n