It’s easy to get the current selection with Javascript. It’s easy to select an entire node.
But what if you want to create a selection that spans multiple elements?
Easy (after a few hours of bumbling around, lol):
- Select the text in the element where you want the block to start (I used
window.find()
)
- Save the start point in a range object with
setStart
- Repeat 1 & 2 with the end point, setting the end of the range object
- Select the (multi-node) range object you just created with
window.getSelection().addRange()
Get the code here.
Enjoy!
If your file templates are missing from Xcode (I’m using 3.2.1), run the following commands in terminal, restart Xcode, and they will be there!
sudo mkdir /Library/Application\ Support/Developer/Shared/Xcode/File\ Templates/
sudo mkdir /Library/Application\ Support/Developer/3.0/Xcode/File\ Templates/
svn co http://svn.macosforge.org/repository/ruby/MacRuby/
trunk/misc/xcode-templates/File%20Templates /Library/Application\ Support/Developer/Shared/Xcode/File\ Templates/
sudo cp -r /Library/Application\ Support/Developer/Shared/Xcode/File\ Templates/* /Library/Application\ Support/Developer/3.0/Xcode/File\ Templates/
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.
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!
Recent Comments