I want to move the position of a current window 5 pixels up, and 5 pixels right.
I do not have RStudio, however, here is an example using Google Chrome.
Example AppleScript code:
if not running of application "Google Chrome" then
return
tell application "System Events"
tell application process "Google Chrome"
if not (exists window 1) then
return
set |position| to position of window 1
set position of window 1 to ¬
{((item 1 of |position|) + 5), ((item 2 of |position|) - 5)}
end if
end tell
end tell
end if
Notes:
Since you didn't state how you intended to implement the AppleScript code, I've included some error handling that may not be necessary, e.g. if not running of application "Google Chrome" then return
block. (Or whichever application you set it for.)
Once a window had been repositioned to where it meets the bottom of the menu bar, or top of the screen if the menu bar is hidden, it will no longer move upwards and will only continue to move to the right.
Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5
, with the value of the delay set appropriately.