I would like to open 4 Finder windows and position them on my desktop.
If possible, I would like to open each windows with another directory.
I had a solution for opening the 4 Finder windows. I was not able to open a specific (always the same) directory.
Today for some reason, I get an error message.
tell application "Finder"
-- get number of open finders
set NumberofFinders to count every Finder window
if NumberofFinders is 0 then
make new Finder window
set the target of Finder window 1 to home
end if
-- close all finders except the frontmost one
if NumberofFinders is greater than 1 then
repeat NumberofFinders - 1 times
close last Finder window
end repeat
end if
-- get screen info
set menueBarHeight to 24
set screenBounds to bounds of window of desktop
set screenWidth to item 3 of screenBounds
set screenHeight to (item 4 of screenBounds) - menueBarHeight
-- move finder and set the size
set the bounds of the front Finder window to {screenWidth * 0.5, screenHeight * 0.5 + menueBarHeight, screenWidth, screenHeight + menueBarHeight}
-- make 2nd finder
make new Finder window
set the target of Finder window 2 to home
set the bounds of the front Finder window to {0, screenHeight * 0.5 + menueBarHeight, screenWidth * 0.5, screenHeight + menueBarHeight}
-- make 3nd finder
make new Finder window
set the target of Finder window 3 to home
set the bounds of the front Finder window to {screenWidth * 0.5, screenHeight * 0, screenWidth, screenHeight * 0.5}
-- make 4nd finder
make new Finder window
set the target of Finder window 4 to home
set the bounds of the front Finder window to {0, 0, screenWidth * 0.5, screenHeight * 0.5}
-- bring the finders to the front
activate
end tell
Ergebnis:
error "„Finder“ received an error: „bounds of window of desktop“ can n ot be read." number -1728 from bounds of window of desktop
Related
A window in this VB6 legacy system that I'm supporting hosts a Word 2007 instance as a child window. On Windows 7, the parent window can be resized without any issues: the window doesn't update until the mouse is released after resizing. On Windows 10, however, the window updates dynamically while being resized.
The issue I'm encountering in Windows 10 is that the child Word window is getting activated/focused upon the first update: you can only drag to resize the parent window by a couple pixels at a time, before the child window gets focused and the resize event on the parent window is canceled (the cursor is still on the resize icon, but continued dragging has no effect). Maximizing, minimizing, and restoring the parent window all work normally. Once the child Word window is closed (through the file menu in Word), the parent window can be resized normally, because there's no child window to activate/focus. The same automatic-child-window-activation-after-parent-window-resizing occurs in Windows 7, but because the resize event doesn't fire until after the parent window has actually updated, it's not an issue there.
My conundrum is that I don't see anything in the code that suggests why the child window is getting automatically activated/focused, unless that's just default Windows behavior. In either case, I'm pretty sure I need a way to make that not happen.
All that this code is explicitly doing (primarily the ResizeControls() sub; the rest is here mostly for context) is resizing/positioning the Word window to correspond to the new size of the container in the parent window, which is consistent with the behavior in Windows 7.
From what I can tell, I don't believe that GetWindow() actually activates the window it gets a handle to, but if it does, then that's likely the cause of the issue, in which case I need to be able to get a handle to the window without activating it.
PDFView.frm:
Begin VB.Form frmPDFView
Caption = "Untitled"
ClientHeight = 8655
ClientLeft = 1320
ClientTop = 1665
ClientWidth = 9270
' ...
Begin VB.PictureBox picContainer
BackColor = &H00FFFFFF&
Height = 4215
Left = 1080
ScaleHeight = 4155
ScaleWidth = 4995
TabIndex = 0
Top = 120
Width = 5055
End
End
Private Sub ResizeControls()
On Error Resume Next
Dim pWndChild As Long
Dim r As RECT
Dim rtn As Long
picContainer.Left = 100
picContainer.Height = Me.Height - 1300
picContainer.Width = Me.Width - 350
picContainer.Top = 300
pWndChild = GetWindow(picContainer.hWnd, GW_CHILD)
rtn = GetLastError
If (pWndChild) Then
rtn = GetClientRect(picContainer.hWnd, r)
rtn = SetWindowPos(pWndChild, 0, 0, 0, r.Right - r.Left, r.Bottom - r.Top, SWP_NOZORDER Or SWP_NOMOVE)
Else
rtn = GetLastError
End If
End Sub
Private Sub Form_Resize()
On Error GoTo ERROR_HANDLER
Call ResizeControls
Exit Sub
ERROR_HANDLER:
Err.Clear
Resume Next
End Sub
Turns out I'm blind and/or didn't read the documentation thoroughly enough for all the Windows functions used in the code. Found the solution the next day and forgot to come back and answer this, but as confirmed by #wqw's comment, the issue was with SetWindowPos(). The SWP_NOACTIVATE flag needed to be passed in to SetWindowPos() to prevent activation of the target window (in my case, the child Word window).
I am trying to find a way to bring up the context menu in Finder on a Mac with Yosemite without touching the mouse/touchpad.
A context menu.
After extensive research on this issue, the only possible route seems to be using AppleScript with Automator, and assign keyboard shortcut to it.
The AppleScript below was found on stackoverflow, if I run it inside the Automator, it would bring up the context menu on one of the files on the desktop (not the file currently selected.)
tell application "System Events"
tell process "Finder"
set target_index to 1
set target to image target_index of group 1 of scroll area 1
tell target to perform action "AXShowMenu"
end tell
end tell
Automator screenshot
But I am having trouble getting it to work with keyboard shortcut.
Also I will need to make sure that it brings the menu for the currently selected file.
Can someone provide some insight about how this can be done?
You can read about the script below here: MacScripter / right click
# Copyright © 2012 - 2015 McUsr
run showRightClickMenu
script showRightClickMenu
on run
set mouseLoc to (do shell script "~/opt/bin/MouseTools -location")
set {astid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
tell mouseLoc to set {mouseX, mouseY} to {it's text item 1, it's text item 2}
set {mouseX, mouseY} to {(mouseX as integer), 1200 - (mouseY as integer)}
tell application id "sevs"
set frontProcessName to name of every process whose frontmost is true
-- tell a to set aa to (get its name)
set wnCount to count of windows of process named frontProcessName
if wnCount > 0 then
tell window 1 of process named frontProcessName
set wnPos to its position
set wnsize to its size
end tell
set {wnX, wnY, wnWidth, wnHeight} to {item 1 of wnPos, item 2 of wnPos, item 1 of wnsize, item 2 of wnsize}
set {leftBound, RightBound, upperBound, lowerBound} to {wnX + 1, (wnX + wnWidth - 21), wnY + 50, (wnY + wnHeight - 51)}
if mouseX ≥ leftBound and mouseX ≤ RightBound then
else if mouseX < leftBound then
set mouseX to leftBound
else
set mouseX to RightBound
end if
if mouseY ≥ upperBound and mouseY ≤ lowerBound then
else if mouseY < upperBound then
set mouseY to upperBound
else
set mouseY to lowerBound
end if
end if
end tell
set mouseLoc to "c" & mouseX & " " & mouseY
do shell script "~/opt/bin/cliclick " & mouseLoc
set AppleScript's text item delimiters to astid
end run
end script
This will bring up the context menu of the currently selected file of the desktop:
tell application "Finder"
set sel to get the selection
if (sel is {}) then
log "Nothing selected! Can't proceed"
return
end if
set target_item_name to the name of (item 1 of sel)
end tell
tell application "System Events"
tell process "Finder"
tell group 1 of scroll area 1
set target to the first image whose value of attribute "AXFilename" is target_item_name
tell target to perform action "AXShowMenu"
end tell
end tell
end tell
*Tested on 10.8.5 in script editor
The first part of this script finds the art size and returns with the size in inches -
I want this to then ask what size to make the width then enter the number and have Illustrator scale the art to the width in the returned dialog.
I'm trying to figure out where the calculation is off here.
It seemed at first the scale percentage would be correct but to enlarge the
percentage must be over 100 % (i.e. 125% or 150% etc.)
I can't get the script to compile with an else between my if's so I'm sure I'm missing something here.
tell application "Adobe Illustrator"
activate
tell document 1
--define Spot1
set docColorSpace to color space
if (docColorSpace is CMYK) then
set SpotColor1 to {cyan:21.0, magenta:0, yellow:100.0, black:0.0}
else
set SpotColor1 to {red:206.0, green:219.0, blue:41.0}
end if
--color change first
set (path items whose fill color is not SpotColor1)'s fill color to SpotColor1
--get current size
set tempGroup to make new group item with properties {name:"TempGroup"} -- Create a temporary container group
duplicate every page item to beginning of group item "TempGroup" -- copy instances to it
set {w, h} to {width, height} of tempGroup -- get properties
delete tempGroup
display dialog "Width of Art: " & (w / 72) & return & "Height of Art: " & (h / 72)
--change to desired size PROBLEM SECTION
set newWidth to text returned of (display dialog "Please enter Art Width:" default answer "100")
tell application "Adobe Illustrator"
set artWidth to width of tempGroup
set sizeDifference to (newWidth / artWidth) * 100
try
if newWidth is equal to artWidth then
set scalePercentage to 100
end if
if newWidth is greater than artWidth then
set scalePercentage to (100 + sizeDifference)
end if
if newWidth is less than artWidth then
set scalePercentage to (100 - sizeDifference)
end if
end tell
end
I appreciate any suggestions. I realize javascript is probably the way to go with Illustrator
but am trying to saw my way through understanding some applescripts before moving on to something more advanced. Thanks in advance.
I found the answer after playing with the math.
The problem was Illustrator doesn't deal with inches only points
hence the (w/72) (h/72) portion when it gets the size.
72 points = 1 inch so the math had to convert points to inches.
like so
tell application "Adobe Illustrator"
activate
tell document 1
--get current size
set tempGroup to make new group item with properties {name:"TempGroup"} -- Create a temporary container group
duplicate every page item to beginning of group item "TempGroup" -- copy instances to it
set {w, h} to {width, height} of tempGroup -- get properties
delete tempGroup
display dialog "Width of Art: " & (w / 72) & return & "Height of Art: " & (h / 72)
--resize
set newWidth to text returned of (display dialog "Please enter Art Width:" default answer "10")
set artWidth to width of tempGroup
set sum to (artWidth / newWidth * 100)
set scalePercentage to (72 / sum * 10000)
scale tempGroup horizontal scale scalePercentage vertical scale scalePercentage
end tell
end tell
end
I'm calling an Applescript from within FilemakerPro.
These are the things I try to achieve:
An image is stored within a container field.
It stores it's name and path in separate fields.
An Applescript is being activated to perform these actions:
It retrieves the data from FilemakerPro
It checks if there is a folder with the same name as the field "calculate_merk_id"
If not, it creates the folder
It creates a new imagefile which name should have "__small" added to his name after it has been resized to 155 x 134, and stores it in this folder
It creates a new imagefile which name should have "__large" added to his name after it has been resized to 400 x 400, and stores it in this folder
The first error I receive is that it cannot retrieve the dimensions of the image. Furthermore, it won't create my resized images ... Anyone who wants to give me a hand in the right direction, please?
set pad to cell "ServerImagePath" of current record
set filenaam to cell "afbeelding_local_vol_pad" of current record
set foldernaam to cell "calculate_merk_id" of current record
set volle_foldernaam to cell "ServerImageFolder" of current record
set volle_filenaam to cell "ServerImageFile" of current record
set target_small_width to 155
set target_small_height to 134
set target_large_width to 400
set target_large_height to 400
tell application "Finder"
if not exists volle_foldernaam then
make new folder at pad with properties {name: foldernaam}
end if
duplicate filenaam to volle_foldernaam with replacing
tell application "Image Events"
launch
set this_image to filenaam
copy dimensions of this_image to {W, H}
if target_small_width is greater than target_small_height then
if W is greater than H then
set the scale_length to (W * target_small_height) / H
set the scale_length to round scale_length rounding as taught in school
else
set the scale_length to target_small_height
end if
else if target_small_height is greater than target_small_width then
if H is greater than W then
set the scale_length to (H * target_small_with) / W
set the scale length to round scale_length rounding as taught in school
else
set the scale_length to target_small_width
end if
else
set the scale_length to target_small_height
end if
scale this_image to size scale_length
pad this_image to dimensions {target_small_width, target_small_height}
save this_image as this_name & "__small"
close this_image
end tell
end tell
You forgot to open the image
set this_image to filenaam
should be
set this_image to open filenaam
Why not do this natively in FileMaker? FM 12 and later have the GetThumbnail() function. A script could calculate a re-sized image into a global field, then export the image from the global field. Completely cross-platform will work on OSX and Windows, even FileMaker Go.
Set Field [ photo_temp_g ; GetThumbnail ( photo_original ; width ; height ) ]
Commit Record/Request []
Export Field Contents [ photo_temp_g ; “<filename>” ]
I'm working on a script to eliminate repetition.What I have so far will obtain the current size of the art in Illustrator and display the size in inches but I'm having trouble figuring out how to scale the art based on a return dialog. I'm trying to get it to scale the art proportionally to the measurement returned for the width. It will then resize the artboard based on the new size of the art (this part works). Here's what I have so far
tell application "Adobe Illustrator"
activate
tell document 1
--define Spot1
set docColorSpace to color space
if (docColorSpace is CMYK) then
set SpotColor1 to {cyan:21.0, magenta:0, yellow:100.0, black:0.0}
else
set SpotColor1 to {red:206.0, green:219.0, blue:41.0}
end if
--color change first
set (path items whose fill color is not SpotColor1)'s fill color to SpotColor1
--get current size
set tempGroup to make new group item with properties {name:"TempGroup"} -- Create a temporary container group
duplicate every page item to beginning of group item "TempGroup" -- copy instances to it
set {w, h} to {width, height} of tempGroup -- get properties
delete tempGroup
display dialog "Width of Art: " & (w / 72) & return & "Height of Art: " & (h / 72)
--change to desired size PROBLEM SECTION
set ArtWidth to text returned of (display dialog "Please enter Art Width:" default answer "10")
try
if (w / 72) is greater than ArtWidth then
set sizeDifference to (ArtWidth - (w / 72)) as integer
else
if (w / 72) is less than ArtWidth then
set sizeDifference to ((w / 72) - ArtWidth) as integer
end if
end if
set has selected artwork of (every layer of document 1) to true
set everyPageItem to artItem
set x1orig to item 1 of activeArt
set y1orig to item 2 of activeArt
set x2orig to item 3 of activeArt
set y2orig to item 4 of activeArt
--not sure if activeArt
--determine new page size (add inch in each direction)
set x1new to (x1orig - sizeDifference) as real
set y1new to (y1orig + sizeDifference) as real
set x2new to (x2orig + sizeDifference) as real
set y2new to (y2orig - sizeDifference) as real
--set new art size
set artItem to {x1new, y1new, x2new, y2new}
--fit artboard to art
set tempGroup to make new group item with properties {name:"TempGroup"} -- Create a temporary container group
duplicate every page item to beginning of group item "TempGroup" -- copy instances to it
set {w, h} to {width, height} of tempGroup -- get properties
set theBounds to visible bounds of tempGroup
set artboard rectangle of first artboard to theBounds
delete tempGroup
-- one inch border
tell artboard 1
--get original page size
set artPage to artboard rectangle
set x1orig to item 1 of artPage
set y1orig to item 2 of artPage
set x2orig to item 3 of artPage
set y2orig to item 4 of artPage
--determine new page size (add inch in each direction)
set x1new to (x1orig - 72) as real
set y1new to (y1orig + 72) as real
set x2new to (x2orig + 72) as real
set y2new to (y2orig - 72) as real
--set new page size
set artboard rectangle to {x1new, y1new, x2new, y2new}
--print to rip, set path to folder
--hop out to finder, close & file folders where they go
end tell
end try
end tell
end tell
end
I'm feel like I'm overlooking an easier way to do this - any suggestions appreciated
This is taken from a subroutine I use for scaling art to a specific width. Notice that the difference in inches doesn't actually matter. You just need to know the scale between the original size and the new size.
set newWidth to text returned of (display dialog "Please enter Art Width:" default answer "10")
tell application "Adobe Illustrator"
set artWidth to width of tempGroup
set scalePercentage to (newWidth / artWidth) * 100
scale tempGroup horizontal scale scalePercentage vertical scale scalePercentage
end tell
The problem with the script was Illustrator works with points rather than inches so I had to convert the points to inches like so
tell application "Adobe Illustrator"
activate
tell document 1
--get current size
set tempGroup to make new group item with properties {name:"TempGroup"} -- Create a temporary container group
duplicate every page item to beginning of group item "TempGroup" -- copy instances to it
set {w, h} to {width, height} of tempGroup -- get properties
delete tempGroup
display dialog "Width of Art: " & (w / 72) & return & "Height of Art: " & (h / 72)
--resize
set newWidth to text returned of (display dialog "Please enter Art Width:" default answer "10")
set artWidth to width of tempGroup
set sum to (artWidth / newWidth * 100)
set scalePercentage to (72 / sum * 10000)
scale tempGroup horizontal scale scalePercentage vertical scale scalePercentage
end tell
end tell
end