Last active
May 5, 2021 15:59
-
-
Save thespacedoctor/b9c720298e89cda6d23f47aea14642e8 to your computer and use it in GitHub Desktop.
[Open Current Scivener File in Marked 2] #marked #scrivener #applescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| property myName : "_display" | |
| property pX : missing value | |
| property pY : missing value | |
| -- GRAB FILEPATH | |
| tell application "System Events" | |
| tell process "Scrivener" | |
| activate | |
| set documentPath to value of attribute "AXDocument" of window 1 | |
| end tell | |
| end tell | |
| set o_set to offset of "/Users" in documentPath | |
| set fixFile to characters o_set thru -1 of documentPath | |
| set documentPath to fixFile as string | |
| set documentPath to do shell script "python -c \"import urllib, urlparse, sys; print urllib.unquote(urlparse.urlparse(sys.argv[1])[2])\" " & quoted form of documentPath | |
| -- ALIGN WINDOW | |
| send_window_half_screen("Scrivener", "left") | |
| -- OPEN IN MARKED | |
| tell application "Marked 2" | |
| activate | |
| open documentPath | |
| end tell | |
| -- ALIGN WINDOW | |
| send_window_half_screen("Marked 2", "right") | |
| -- SOURCE: https://github.com/RobTrew/txtquery-tools/blob/master/utilities/OpeniThoughtsMapinMarked.applescript | |
| -- CREDIT: Rob Trew (https://twitter.com/complexpoint) | |
| on displayResoln() | |
| if (pX is missing value) or (pY is missing value) then | |
| set {dlm, my text item delimiters} to {my text item delimiters, "Resolution"} | |
| set lstDisplays to text items of (do shell script "system_profiler SPDisplaysDataType") | |
| repeat with i from 2 to length of lstDisplays | |
| set strLine to item i of lstDisplays | |
| if strLine contains "Main Display: Yes" then exit repeat | |
| end repeat | |
| set my text item delimiters to space | |
| set lstParts to text items of strLine | |
| set my text item delimiters to dlm | |
| set {strX, strY} to {item 2, item 4} of lstParts | |
| set {pX, pY} to {strX as integer, strY as integer} | |
| -- fix for retina display | |
| if {pX, pY} is equal to {2880, 1800} then | |
| set {pX, pY} to {1920, 1200} | |
| end if | |
| if {pX, pY} is equal to {6720, 3780} then | |
| set {pX, pY} to {3360, 1890} | |
| end if | |
| end if | |
| return {pX, pY} | |
| end displayResoln | |
| -- summary of function | |
| on send_window_half_screen(appName, windowPosition) | |
| -- variables -- | |
| set windowSize to 0.5 | |
| set windowMargin to 5 | |
| tell application "System Events" | |
| -- The screen dimensions | |
| set {displayWidth, displayHeight} to my displayResoln() | |
| -- get the app process | |
| set appProcess to application processes where name contains appName | |
| -- set some window variables | |
| set leftRightWindowWidth to ((displayWidth * windowSize) as integer) - windowMargin * 2 | |
| set topBottomWindowHeight to ((displayHeight * windowSize) as integer) - windowMargin * 2 | |
| set fullWindowHeight to displayHeight - windowMargin * 2 | |
| set fullWindowWidth to displayWidth - windowMargin * 2 | |
| if appProcess is not equal to {} then | |
| tell process appName | |
| if value of attribute "AXFullScreen" of window 1 then | |
| set value of attribute "AXFullScreen" of window 1 to false | |
| delay 1.5 | |
| end if | |
| end tell | |
| set appWindow to front window of (item 1 of appProcess) | |
| if windowPosition is equal to "left" then | |
| tell appWindow to set {position, size} to {{windowMargin, windowMargin}, {leftRightWindowWidth, fullWindowHeight}} | |
| else if windowPosition is equal to "right" then | |
| tell appWindow to set {position, size} to {{leftRightWindowWidth + windowMargin * 3, windowMargin}, {leftRightWindowWidth, fullWindowHeight}} | |
| else if windowPosition is equal to "top" then | |
| tell appWindow to set {position, size} to {{windowMargin, windowMargin}, {fullWindowWidth, topBottomWindowHeight}} | |
| else if windowPosition is equal to "bottom" then | |
| tell appWindow to set {position, size} to {{windowMargin, topBottomWindowHeight + windowMargin}, {fullWindowWidth, topBottomWindowHeight}} | |
| end if | |
| end if | |
| end tell | |
| end send_window_half_screen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment