Weirdness with file Open and Applescript
apple Verified ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
I am trying to do some script debugging. It requires the opening of the same file each time the script is run. When I execute the following script,
set workFile to choose file with prompt "Choose Work File"
tell application "Numbers"
open workFile
end tell
multiple times, instead of Numbers just reusing the open file, Numbers opens another document with the same file. I am used to an app just using the open file without opening another document. This behavior doesn't seem to conform to what I am use to with other scriptable apps.
Others care to comment?
8 replies
Sign in or join Beachball Help to reply.
- 0
Apple Support Community member ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
The behavior is perfectly logical if your preferences are set to "Use the template: myDefault.template"
If you set it to "Show the list of templates" (translated from French), there is no extraneous document.
Stay tuned, I will post a piece of code to set the preference on the script entry and reset the original one on the script exit.
Alas, I'm afraid that this will require that we close the app then re-open it as we may only change the preferences file, not the copy used in memory.
Yvan KOENIG (from FRANCE dimanche 11 janvier 2009 14:23:48)
- 0
Apple Support Community member ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Here is the script.
--[SCRIPT]
set iWork08 to false
if iWork08 then
set leProcess to "Numbers"
set propertyName to "LSDefaultsUseDefaultStartingPoint"
set prefName to "com.apple.iWork.Numbers.plist"
set test to true
else
set leProcess to "Numbers" --"Numbers09"
set propertyName to "ShowStartingPointsForNewDocument"
set prefName to "com.apple.iWork.Numbers.plist" --"com.apple.iWork09.Numbers.plist"
set test to false
end if
set p2p to (path to preferences) as text
set p2pref to p2p & prefName
tell application "System Events"
set appfile to "" (* default value *)
set oldSetting to get value of property list item propertyName of property list file p2pref
if oldSetting is test then
set value of property list item propertyName of property list file p2pref to (not test)
set lesProcess to get title of every process
if leProcess is in lesProcess then
set theAppFile to (get file of process leProcess) as text
my quitApp(theAppFile)
my openApp(theAppFile)
end if -- leProcess …
end if -- oldSetting …
end tell
(*
set workFile to choose file with prompt "Choose Work File"
tell application theappfile
open workFile
end tell
*)
tell application "System Events"
if oldSetting is test then
set value of property list item propertyName of property list file p2pref to test
if theAppFile is not "" then
my quitApp(theAppFile)
my openApp(theAppFile)
end if
end if
end tell
--=====
on quitApp(a)
tell application a to quit
delay 1 (* maybe too long but a pause is required *)
end quitApp
--=====
on openApp(a)
tell application a
activate
end tell
end openApp
--=====
--[/SCRIPT]Yvan KOENIG (from FRANCE dimanche 11 janvier 2009 15:51:17)
- 0
Apple Support Community member ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Thanks for your input. I think you have missed my point because I wasn't clear enough. On further exploration, my problem is with Numbers and "dirty" documents. A "dirty" document is any document that would ask for a save upon closing. Examples of files that would create dirty documents in Numbers would be a CSV or a Numbers 08' file.
"My script would work without a quit if it where a clean document, independent of the pref settings.
Try this. It will show the behavior I don't like, using just Numbers, no scripting. A similar problem occurs with scripting, though.
1. Open a file, any file in Numbers that creates a "dirty" document.
2. Open that same file in Numbers again.Results: Notice that Numbers opens another window with the same file.
Expected results: Bring the open file's window to the front.This is different than just about every app that I have used up to this time.
Try this in TextEdit.
1. Open a file in TextEdit.
2. Add a space so that the file is dirty.
3. Open the same file from step 1.Notice it doesn't open a new window.
That would be the behavior I would expect in Numbers.
- 0
Apple Support Community member ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
I can reproduce your issue with CSV and Excel files, but not with .numbers ('08 or '09). When a CSV or Excel file is opened by Numbers, it is imported and retains no connection with the original file. These are marked as dirty, as they have never been saved (it helps if you distinguish between saving and exporting).
Numbers files are native, and have a proper connection between document and file. An '08 file is marked as dirty, since saving it will alter the original.
For TextEdit, text, and RTF are native file formats, so you don't see this behavior.
- 0
Apple Support Community member ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Thank you much for your further research and explanation. You have helped me to further understand and focus on the point I am trying to make.
Numbers handles the behavior of native and non-native files differently. As a former programmer it makes perfect sense that these cases might be handled differently. But, view it as a end user might see it. Why should Numbers handle these two cases differently? It is inconsistent. Why should I have to know there is a difference between native and non-native files? On second thought why should I have to know there are such things as native and non-native files.
As a user, I see Numbers handling these cases differently and I say inconsistently; Native files don't open another window, non-native files do. It is inconsistent not only with itself but also with hundreds of programs I have used dating back to the days of Apple System 6.0.3. Inconsistency is bad. Inconsistency leads to confusion, uncertainty and frustration.
For a good and fun read take a look at a classic book, "The design of Everyday Things" by Donald A. Norman. It takes a look at how products and software are produced and used. It speaks to consistency in interfaces. I'm pretty sure you would freak if on the way to work tomorrow you hit the brakes but sped up. And the harder you hit the brakes the faster you went. That would be an inconsistent interface and similar though not as extreme as this example with Numbers.
I plan to use Apple products for years to come, but I'd rather not have to ask why simple tasks seemingly behave differently.
Sorry for rambling on so long.
- 0
Apple Support Community member ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
From my point of view, there is no inconsistency.
It's our duty, when we write a script, to take care of the kind of document we are trying to open with a program.
If the document is a native one we have a behavior,
if it is not a native one, we have an other behavior.It's perfectly logical and perfectly coherent.
Yvan KOENIG (from FRANCE lundi 12 janvier 2009 11:11:54)
- 0
Apple Support Community member ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
You are missing my point. I don't want to or need about native vs. non-native files. I just the function of opening to work the same way for any case. It doesn't.
- 0
Apple Support Community member ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
I perfectly understood what you wrote.
But you gave your advice, not the rule.
The rule is defined by Apple not by you StepenM.And the defined rule is:
behaves a way for native documents
behaves an other way for foreign documents.From my point of view, it's perfectly logical.
The application is designed to use its native format.
Importing a foreign file needs a "translation" which means that we get a NEW document so, this one is treated as a 'never saved' one (what you call 'dirty').All foreign formats behaves this way because Numbers perfectly knows that 'translation' is 'trahison'.
If you don't like this behavior, better use a non Apple program.
Yvan KOENIG (from FRANCE lundi 12 janvier 2009 12:22:22)