Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac: a certain range of ints doesn't get transferred #227

Closed
fzumstein opened this issue Sep 20, 2015 · 1 comment
Closed

Mac: a certain range of ints doesn't get transferred #227

fzumstein opened this issue Sep 20, 2015 · 1 comment
Labels
Milestone

Comments

@fzumstein
Copy link
Member

from appscript import app

# Works
app('Microsoft Excel').workbooks['Sheet1'].active_sheet.cells['$A$1:$A$1'].value.set(1)

# Doesn't work
app('Microsoft Excel').workbooks['Sheet1'].active_sheet.cells['$A$2:$A$2'].value.set(2999999999)

# Works
app('Microsoft Excel').workbooks['Sheet1'].active_sheet.cells['$A$3:$A$3'].value.set(float(2999999999))

# Works
app('Microsoft Excel').workbooks['Sheet1'].active_sheet.cells['$A$4:$A$4'].value.set(1.22e19)
@fzumstein fzumstein added the bug label Sep 20, 2015
@fzumstein fzumstein added this to the v0.4.1 milestone Sep 20, 2015
@fzumstein fzumstein changed the title Mac: some ints don't get transferred Mac: fibonancci sample: some values don't get transferred Sep 20, 2015
@fzumstein fzumstein changed the title Mac: fibonancci sample: some values don't get transferred Mac: a certain range of ints doesn't get transferred Sep 22, 2015
@fzumstein
Copy link
Member Author

Answer by Hamish Sanderson, developer of the appscript package:

AppleScript packs integers larger than SInt32 as typeIEEE64BitFloatingPoint (aka Double).

Py-appscript packs integers larger than SInt32 but smaller than SInt64 as typeSInt64, and integers larger than SInt64 as typeIEEE64BitFloatingPoint.

This gives better precision (since Doubles can't encode the full range of 64-bit ints without loss), but can cause compatibility issues with applications that only expect typeSInt32 or typeIEEE64BitFloatingPoint. Applications are supposed to coerce descriptors to the types they require when unpacking them (e.g. coerce to typeSInt32, and if that fails coerce to typeIEEE64BitFloatingPoint), but some of the naughtier Carbon ones just check the descriptor types directly and throw an error if it's not exactly what they expect.

You can either hack the aem.aemcodecs.Codecs.packInt() method to mimic the AppleScript way of doing things more closely, or just cast integers larger than SInt32 to doubles before passing them to Excel, as your examples do. With the rest of the world moving to 64-bit, py-appscript's current behavior is not unreasonable, though it's the sort of thing for which I'd have traditionally put in a 'mimic AppleScript exactly' compatibility switch (the Codecs class already contains several of these). Py-appscript maintenance is very low priority for me these days, but I'll make a note of it for the SwiftAE bridge I'm now working on (https://bitbucket.org/hhas/swiftae).

HTH

has

fzumstein added a commit that referenced this issue Sep 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant