This is a revisited/simplified version of this old post.
You can get more scripts like this from Saekiさん's post
Showing posts with label applescript. Show all posts
Showing posts with label applescript. Show all posts
Wednesday, May 2, 2012
Tuesday, July 26, 2011
Switching back to the previous application with AppleScript
If you want to simulate cmd + tab with AppleScript, here it is
You can use the same thing in bash
tell application "System Events"
tell process "finder"
activate
keystroke tab using {command down}
end tell
end tell
You can use the same thing in bash
echo 'tell application "System Events"
tell process "finder"
activate
keystroke tab using {command down}
end tell
end tell' | osascript
Tuesday, July 5, 2011
Resize and position windows with AppleScript
-- get the dimensions of the desktop, set up few variables
tell application "Finder"
set displayAreaDimensions to bounds of window of desktop
set x1 to item 1 of displayAreaDimensions
set y1 to item 2 of displayAreaDimensions
set x2 to item 3 of displayAreaDimensions
set y2 to item 4 of displayAreaDimensions
end tell
set width to x2 - x1
set height to y2 - y1
-- positioning iTunes, make it fullscreen
tell application "iTunes"
set the bounds of the first window to {x1, y1, x2, y2}
end tell
-- positioning Safari, halfwidth on the right
tell application "Safari"
set the bounds of the first window to {x1 + width / 2, y1, x2, y2}
end tell
-- positioning iTerm
tell application "iTerm"
set the bounds of the first window to {x1, y1, x1 + 1000, y1 + 600}
end tell
There are few useful blogposts about the topic.
www.ithug.com/2007/09/applescript-moving-and-resizing-windows or
www.ithug.com/2008/12/applescript-arranging-multiple-windows/
or you can use Divvy, which is an amazing window management app.
Wednesday, February 2, 2011
Reload the browser when files change on OSX
Web front-end development often looks like this, you change the code, which can be HTML, CSS, JavaScript, Ruby whatever and then you head over to the browser and reload it to see the changes.
This is not a big deal, but what if the browser could automatically does the reload.
My solution has three parts.
In my case this looks like this
You can find the reload_browser.applescript here and the focus-textmate.applescript here.
This is not a big deal, but what if the browser could automatically does the reload.
My solution has three parts.
- You can detect file change with Kicker.
- Set the focus to the browser and reload it with AppleScript.
- Set the focus back to your texteditor.
kicker -e "osascript reload-browser.applescript;focus-textmate.applescript" FOLDER_TO_WATCH
In my case this looks like this
kicker -e "osascript ~/workspace/MacGyver/reload-browser.applescript;osascript ~/workspace/MacGyver/focus-textmate.applescript" src/
You can find the reload_browser.applescript here and the focus-textmate.applescript here.
Monday, December 20, 2010
Open a new tab with AppleScript in Chrome
tell application "Google Chrome"
set myTab to make new tab at end of tabs of window 1
set URL of myTab to "http://google.com"
end tell
more AppleScript Chrome goodies at http://laclefyoshi.blogspot.com/2010/10/google-chrome-ver.html
Tuesday, December 14, 2010
Reload the browser with AppleScript
This post is obsoleted, here is the new simplified version.
AppleScript is a weird language but you still can do cool things with it.
Please feel free to replace "Google Chrome" with your choice.
https://github.com/yikulju/MacGyver/blob/master/reload-browser.applescript
AppleScript is a weird language but you still can do cool things with it.
tell application "Google Chrome"
activate
end tell
tell application "System Events"
tell process "Google Chrome"
keystroke "r" using {command down}
end tell
end tell
Please feel free to replace "Google Chrome" with your choice.
https://github.com/yikulju/MacGyver/blob/master/reload-browser.applescript
Subscribe to:
Posts (Atom)