Archive

Posts Tagged ‘Applescript’

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: ,

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: , , ,

PersonalBrain and VoodooPad

October 27th, 2009 No comments

I created an Applescript in response to the PersonalBrain Forums, which launches a VoodooPad page from the current active thought in PersonalBrain:

– Copy name of active thought

tell application “PersonalBrain” to activate

set old_clipboard to the clipboard

set the clipboard to “”

repeat while (the clipboard) is “”

tell application “System Events”

tell process “PersonalBrain”

perform action “AXPress” of menu item “Copy as Text” of menu 1 of menu bar item “Edit” of menu bar 1

end tell

end tell

end repeat

– Strip trailing newline

set active_thought_name to (characters 1 thru -2 of (get the clipboard)) as string

– If page does not exist in VoodooPad, create it

– Open page in VoodooPad

tell application “VoodooPad”

activate

tell document 1

open page with name active_thought_name

end tell

end tell

set the clipboard to old_clipboard

VoodooPa

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: , , ,

Applescript Studio Debugger/Breakpoint Fiasco

July 16th, 2009 No comments

I was working on an Applescript Studio project with Objective-C mixed in, when all of a sudden, without any warning or intervention from me, the debugger ceased to load when I ran the app (in debug mode). Hmmm, little gremlins, hackers from Russia???

After searching the lists and checking off the usual culprits (debug configuration, yes; debug symbols enabled, ditto), I went to my old-standby-last-resort-when-xcode-starts-acting-crazy-for-no-reason move: I created a fresh project, confirmed that it was working normally, and then opened every setting window in both projects to see what settings are different, and so could possible be contributing to the hiccup.

When I opened the settings for the executable (I was desparate), I noticed that the “Debugging->When using…” drop-down was different. Now, to you or I, “when using” seems to say “these setting only apply when you happen to be using X.” Yet on planet Xcode, it seems to translate into “when you change X, you’re project will begin to work in a different way then usual, even if you do not change any o the settings in this window.” I selected “GDB” from the drop-down, and all my problems were solved… maybe that’s a bit dramatic.

Anyway, my breakpoints are again working (in both the Obj-C and applescript code). Yay!

Categories: Mac, Programming, Xcode Tags: , ,

Applescript to add inclusion guards to C++ Header files in Xcode

April 26th, 2009 No comments

I got tired of manually adding them, so here’s a little script…

set list_lib to load script alias “Path:To:List Utilities.scpt”

tell application “Xcode”

Get file name of front-most document (via window)

set header_file_path to associated file name of window 1

 

Go back and get the source file using the name

set header_file to first source document whose path is header_file_path

Turn the file into a list of lines to
— find the insertion point for the inclusion guard

set lines_of_header to paragraphs of text of header_file

Create the inclusion guard based on the file name

set inclusion_guard_token to first word of (get name of header_file) 
& “_H_INCLUDED_”

set guard_start to “\n#ifndef “ & inclusion_guard_token 
& “\n” & “#define “ & inclusion_guard_token & “\n”

 

Insert the start of the guard

set lines_of_header to list_lib‘s list_insert(lines_of_header, guard_start, 9)

Insert the end of the guard

set end of lines_of_header to “\n\n#endif”

Set the revised contents of the file

set text of header_file to (lines_of_header as text)

end tell

List Utilities.scpt (code from AppleScript: The Definitive Guide, 2nd Edition:

on find_in_list(what, L)

repeat with i from 1 to count L

if item i of L is what then

return (a reference to item i of L)

end if

end repeat

return

end find_in_list

on list_insert(L, what, ix)

if ix = 1 then

return {what} & L

else

return {item 1 of L} & list_insert(rest of L, what, ix - 1)

end if

end list_insert

Categories: Mac, Programming Tags: , ,

Automate acceptance/unit testing C++ in Xcode

April 13th, 2009 2 comments

In my quest to automate all repetitive tasks, setting up a Xcode project for unit testing (using Boost.Test) is in my crosshairs.  I’m in the process of adopting BDD, so you’ll see that terminology mixed with that of unit testing.

Plan

  1. List out all the manual steps.  I started with the process described by Richard Dingwall in a very nice tutorial here.
  2. Implement task in Applescript
Manual process

Ok, so here’s what I do when I start a new C++ project…

  1. File->New Project…
  2. Add Group “Features” @ [project-directory]/Features
  3. Add Group “Specifications” @ [project-directory]/Specifications
  4. Add Group “Boost Test Common” @ [project-directory]/Boost Test Common
  5. Add XcodeLogFormatter.h (allows Boost.Test reports to be properly displayed in Xcode build results; see below) and run_tests.cpp (Boost.Test’s main function) to Boost Test Common
  6. Add Features Target
    1. Add->”New Target”
    2. BSD->Shell Tool
    3. Name: Features
    4. Add run_tests.cpp to “Compile Sources”
    5. Add “/usr/local/include/boost-1_38/” to “Header Search Paths” of Features Target
    6. Add->New Build Phase->New Run Script Build Phase
    7. Script: “${TARGET_BUILD_DIR}/${EXECUTABLE_NAME}” (this causes the Features to be run every time the target is built)
  7. Add Specification (i.e. unit tests) Target: repeat step 6 above for “Specifications”
  8. Add->Existing Files->[boost unit test library]; check Targets: “Features” and “Specifications”
Applescript

Finally done!  Here’s the script and Xcode library script.

Not Doing Now

As I work, I make a list of things that would be nice to have, but are not important enough to think about right now and would take me away from my task:

  1. Put Boost Test Common files in a commonly accessible include folder

Source Code

XcodeLogFormatter.h (from http://richarddingwall.name/category/xcode/):

#include <boost/test/included/unit_test.hpp>

struct xcode_log_formatter :
public boost::unit_test::output::compiler_log_formatter
{
// Produces an Xcode-friendly message prefix.
void print_prefix(std::ostream& output,
boost::unit_test::const_string file_name, std::size_t line
{
output << file_name << ‘:’ << line << “: “;
}
};

run_tests.cpp (from http://richarddingwall.name/category/xcode/):

#define BOOST_AUTO_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include “XcodeLogFormatter.h”

// Set up the unit test framework to use an xcode-friendly log formatter.
struct xcode_config {
xcode_config() {
boost::unit_test::unit_test_log.set_formatter( new xcode_log_formatter );
}
~xcode_config() {}
};

// Call our fixture.
BOOST_GLOBAL_FIXTURE(xcode_config);

(updated) Check out the finished AppleScripts:
1. main script @ http://seandenigris.com/blog/files/Make%20new%20C++%20project.scpt
2. Xcode handler library script @ http://seandenigris.com/blog/files/Xcode.scpt

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