I'm using Mac OS X Mavericks and JDK 1.7.45 to package a Swing application using the javafxpackager tool for Mac. Unfortunately the end result looks like this (hid the icon/name):
Scrolling a bit to the right clarifies the picture:
Apparently the Applications image was placed incorrectly within the DMG. I have no idea how that can happen or what I might have done that triggered this, I just used the standard NetBeans packaging script. Any hints or directions would be appreciated.
OK this turned out to be rather simple, it seems that the tool generates the script:
tell application "Finder"
tell disk "MyApplication"
open
set current view of container window to icon view
set toolbar visible of container window to false
set statusbar visible of container window to false
-- size of window should match size of background
set the bounds of container window to {400, 100, 917, 370}
set theViewOptions to the icon view options of container window
set arrangement of theViewOptions to not arranged
set icon size of theViewOptions to 128
set background picture of theViewOptions to file ".background:background.png"
-- Create alias for install location
make new alias file at container window to POSIX file "/Applications" with properties {name:"Applications"}
-- First, move all files far enough to be not visible if user has "show hidden files" option set
-- Note: this only make sense if "hidden" files are also visible on the build system
-- otherwise command below will only return list of non-hidden items
set filesToHide to the name of every item of container window
repeat with theFile in filesToHide
set position of item theFile of container window to {1000, 0}
end repeat
-- Now position application and install location
set position of item "MyApplication" of container window to {120, 135}
set position of item "Applications" of container window to {390, 135}
close
open
update without registering applications
delay 5
end tell
end tell
Which is problematic since it only delays for 5 (I assume seconds) so I increased this to 20 and it worked. The script should be placed under package/macosx/MyApplication-dmg-setup.scpt.
Related
I am currently using applescript to setup various parameters of the desktops at my university. So far my script successfully changes the desktop background and the dock size.
The problem at hand is when I run the script, majority of the time, the icons on the desktop never change.
Here is the script I wrote to alter the desktop icon's size and grid spacing:
tell application "System Events"
set finderPrefsFile to property list file "~/Library/Preferences/com.apple.Finder.plist"
tell finderPrefsFile
tell property list item "DesktopViewSettings"
tell property list item "IconViewSettings"
set value of property list item "gridSpacing" to "100"
set value of property list item "iconSize" to "32"
set value of property list item "arrangeBy" to "none"
end tell
end tell
end tell
end tell
#Restart Finder for changes to take effect.
do shell script "killall Finder"
How should I go about altering the script to make it work all the time (I would like to eventually share this script with some of my classmates).
P.s.
Here is the full script
I didn't get your script work reliable. I played around with timeouts but didn't get the Finder to refresh using the new settings.
But I found to set some view options directly using vanilla AppleScript:
tell application "Finder"
activate
set iconViewOptions to desktop's window's icon view options
tell iconViewOptions
set arrangement to not arranged
set icon size to 32
set shows item info to false
set shows icon preview to false
end tell
quit
end tell
delay 1
tell application "Finder" to activate
The AppleScript quit-handler works more reliable then do shell script "killall Finder", maybe the killall is too hard...
The delay 1 does the magic to give the Finder the time to breath before get up again and using it the Script works each time...
But one thing is AFAIK not possible in Finder scripting: Setting the grid space :-/
Greetings, Michael / Hamburg
I have this very simple AppleScript:
tell application "Finder"
activate
set |Window| to get Finder window 1
set the current view of |Window| to icon view
set |View Options| to icon view options of |Window|
set the icon size of |View Options| to 256
set the label position of |View Options| to bottom
set the shows item info of |View Options| to true
set the shows icon preview of |View Options| to true
set the arrangement of |View Options| to arranged by name
end tell
which worked perfectly well until Mavericks. Ok, it still runs but the desired effect is missing. Nothing, absolutely nothing happens any more.
Anybody knows what changed with the new version of OS X?
Update 1:
Now i noted that the changes do happen — after a Finder restart. So it might (or might not) be related to this question then «Finder update/refresh applescript not working in 10.8» — Only that I did not have a problem with 10.8 it only appeared with 10.9
I simple fix that may help for now, is to add a close window and open window to the script.
tell application "Finder"
activate
set |Window| to get Finder window 1
set the current view of |Window| to icon view
set |View Options| to icon view options of |Window|
set the icon size of |View Options| to 256
set the label position of |View Options| to bottom
set the shows item info of |View Options| to true
set the shows icon preview of |View Options| to true
set the arrangement of |View Options| to arranged by name
set flipTarget to folder "Users" of startup disk
set targ to target of |Window|
set target of |Window| to flipTarget
set target of |Window| to targ
(* --close |Window|
--open targ
*)
end tell
Not ideal, but until someone works out how to solve this bug. And I call it a bug for want of a better explanation. It may do.
The script collects the target of window one. Closes window 1. Then opens the target of what was window 1.
I suspect this bug is related to the fact that in Mavericks if you open up an applications preference plist file and make a change. The change may not take effect as they used to do in pre 10.9. I think this is because of a change to how the preferences are read and when they are read. I t seems that what is in the memory will take presidents over manual changes. They do however change straight away if you use the unix command defaults.
***UPDATE*1
In Martin's answer there is a good idea of just flipping the target.
But with the problem of not working on a root directory.
The simple answer to that is to use a specific flip target. In this cae the users home folder. We all have on of those..
I have update the last part of the code and comment out the old bit.
The change code is
set flipTarget to folder "Users" of startup disk
set targ to target of |Window|
set target of |Window| to flipTarget
set target of |Window| to targ
#markhunte is right – it seems to be a bug and one needs to reopen the window or similar to get around it. On macscripter.net I found some additional infos. My current version is now (learned other new tricks as well):
tell application "Finder"
activate
tell Finder window 1
set current view to icon view
set its icon view options's properties to {icon size:64, label position:bottom, shows item info:true, shows icon preview:true, arrangement:arranged by name}
-- we refresh the window to reflect the icon size change!
set Original_Target to its target as alias
set Parent_Target to container of its target as alias
set target to Parent_Target
set target to Original_Target
end tell
end tell
This solution does not need to close the window but only changes its target. In the script editor you see the window flashing — but when started from the script menu it is so fast you don't notice any more.
Disadvantage of this solution over #markhunte solution: Won't work on the root directory.
I am trying to get the foreground application from my second monitor (In Mavericks, second desktop). Here's my code that only gets the foreground application:
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
end tell
How can I change it so it gets the application from a specific desktop / screen?
I don't think you can do as you want. If you look at the properties of frontApp there is no property that would indicate which screen it is on. However, what you can do is check the location of the application's windows. If you get the properties of a window of a process then you will see that it has a "position" property. You could check those coordinates to determine which screen it is on.
For example, I have 2 screens. My laptop is setup to be the main screen. I know the screen resolution of the main screen is 1680x1050. Therefore, if I check a window and it has a position outside of those coordinates then I know it must be on the second monitor. Here's how I could do that.
NOTE: I can tell which applications have windows on the second monitor, but not which application on the second monitor is frontmost... like you asked. You'll have to figure something else out for that. I'm showing you this as an idea that maybe you can make workable for your situation.
Here I am only getting the first application with a window on the second monitor. This should show you the idea and you can adjust the code to do as you need.
set mainScreenResX to 1680
set mainScreenResY to 1050
tell application "System Events"
set firstFoundAppOnSecondScreen to missing value
set visibleApps to application processes whose visible is true
repeat with visibleApp in visibleApps
try
tell visibleApp
set {x, y} to position of window 1
if x > mainScreenResX or x < 0 or y > mainScreenResY or y < 0 then
set firstFoundAppOnSecondScreen to name
exit repeat
end if
end tell
end try
end repeat
return firstFoundAppOnSecondScreen
end tell
I need some help for my appleScript.
For all open windows, I want to know which one is hidden (in the dock), which one is visible and which one is focused?
To list windows I use :
tell application "System Events"
set procs to processes
set windowName to {}
repeat with proc in procs
try
if exists (window 1 of proc) then
repeat with w in windows of proc
copy w's name to the end of windowName
end repeat
end if
end try -- ignore errors
end repeat
end tell
return windowName
I tried focused property:
copy w's focused to the end of windowName
and selected property:
copy w's selected to the end of windowName
But this doesn't work!
Thanks for help!
On Mac OS X 10.6 (AppleScript 2.1.2) the description property of a window of an application process (in System Events' terms) is "dialog" if the window is miniaturized (in the Dock), and some other value (such as "standard window", but can be something different depending on the application) if it's not miniaturized.
When an application is hidden altogether (using cmd+H or the "Hide" command from the application's menu), all of its windows will be hidden, regardless of whether they were miniaturized or not, so to find out whether it's hidden, use
visible of application process "<ProcessName>"
It's false when the application is hidden. To un-hide it, set that property to true.
To find out which window of an application is currently focused (frontmost/active), use
window 1 of application process "<ProcessName>"
The list of windows of an application (returned by windows of application process...) is ordered by the vertical stack: the frontmost window is first, the one behind it is second, and so on.
Since in OS X only one application is frontmost at a time, and only one window is in the foreground, you'll get at the currently focused window like this:
window 1 of (first application process whose frontmost is true)
I'm using the following Applescript to set up a .dmg folder's settings, icon spacing, and so on:
on run argv
tell application "Finder"
set diskname to item 1 of argv
tell disk diskname
open
set current view of container window to icon view
set toolbar visible of container window to false
set statusbar visible of container window to false
set bounds of container window to {400, 100, 900, 699}
set theViewOptions to the icon view options of container window
set arrangement of theViewOptions to not arranged
set icon size of theViewOptions to 100
set background picture of theViewOptions to file "background.png"
set file_list to every file
repeat with i in file_list
if the name of i is "Applications" then
set the position of i to {368, 135}
else if the name of i ends with ".app" then
set the position of i to {134, 135}
end if
-- Change the 7 to change the color: 0 is no label, then red,
-- orange, yellow, green, blue, purple, or gray.
set the label index of i to 7
end repeat
update without registering applications
delay 4
end tell
end tell
end run
The window's being set up correctly, with one exception: the 500x600 background.png image is shrunk to about a third of the original size and placed in the upper left corner. I can't explain why this is happening. Any suggestions?
Boy, this is really st00pid.
I ran into this problem on OS X Lion. It turns out that Lion requires that the background image for a folder be set to 72 DPI. The image I was using was 200 DPI, so Lion scaled it down from its actual pixels.
I re-saved the image with a declared resolution of 72 DPI, and it works perfectly.