Skip to content

Commit

Permalink
Merge pull request #39 from RhetTbull/bug_version_check_locale_38
Browse files Browse the repository at this point in the history
Bug version check locale 38
  • Loading branch information
RhetTbull authored Nov 14, 2022
2 parents 83d5727 + a266968 commit 4abb7d6
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.0
current_version = 0.2.1
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
serialize = {major}.{minor}.{patch}

Expand Down
2 changes: 1 addition & 1 deletion photoscript/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
""" version info """

__version__ = "0.2.0"
__version__ = "0.2.1"
63 changes: 54 additions & 9 deletions photoscript/photoscript.applescript
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
(* AppleScript methods used by PhotoScript (https://github.com/RhetTbull/PhotoScript) *)

-- TODO: Variable names are not very consistent throughout this, some use leading _ some trailing_
-- underscore is used because some variable names (like folder) would clash with AppleScript nouns
-- but this won't be maintainable if naming scheme isn't consistent
-- Naming scheme is classNameMethodName

-- Naming scheme is _classname_methodname
---------- Constants ----------

(* max number of times to retry in case of error
some AppleScript calls appear to be flaky and don't always execute
so retry those up to MAX_RETRY if not succesful
*)
-- max number of times to retry in case of error
-- some AppleScript calls appear to be flaky and don't always execute
-- so retry those up to MAX_RETRY if not succesful
property MAX_RETRY : 5

-- max time in seconds to wait for Photos to respond
property WAIT_FOR_PHOTOS : 300


Expand Down Expand Up @@ -770,7 +772,8 @@ end folderGetFolderForID
on folderExists(_id)
(* return true if folder with _id exists otherwise false *)
photosLibraryWaitForPhotos(WAIT_FOR_PHOTOS)
set version_ to photosLibraryVersion() as number
set versionString to photosLibraryVersion()
set version_ to stringToNumber(versionString)
if version_ < 5 then
tell application "Photos"
try
Expand Down Expand Up @@ -1209,7 +1212,7 @@ on photoSpotlight(id_)
end tell
end photoSpotlight

--------- Utilities ----------
---------- Utilities ----------

use framework "Foundation"

Expand All @@ -1221,6 +1224,48 @@ on revealInFinder(itemList)
tell theWorkspace to activateFileViewerSelectingURLs:itemList
end revealInFinder

on replaceChars(stringValue, findChars, replaceChars)
(* replace findChars in stringValue with replaceChars
Args:
stringValue: a string to search
findChars: string of one or more characters to find in stringValue
replaceChars: string of one of more characters to use as replacement for findChars
Returns:
string with replacements made
*)
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to the findChars
set the itemList to every text item of stringValue
set AppleScript's text item delimiters to the replaceChars
set newString to the itemList as string
set AppleScript's text item delimiters to oldDelimiters
return newString
end replaceChars

on stringToNumber(strValue)
(* Converts a string representation of real number in form x.y or x,y into a number
This is required because AppleScript throws in error with " "7.0" as number "
in locales that use "," as the decimal separator, expecting "7,0"
Args:
strValue: string value to return
Returns:
number
*)

try
return strValue as number
on error
-- assume we're in a locale that uses , as decimal separator and try again
return replaceChars(strValue, ".", ",") as number
end try
end stringToNumber

--------- Test ----------
(* tell application "Photos"
set folder_ to folder id ("65E8932D-5746-465A-8B64-EE1FA2EB0B4A/L0/020") of folder id ("216F08FA-5F50-4944-99DA-042C1AEDFAEC/L0/020")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "photoscript"
version = "0.2.0"
version = "0.2.1"
description = "Python wrapper around Apple Photos applescript interface"
authors = ["Rhet Turnbull <rturnbull+git@gmail.com>"]
license = "MIT License"
Expand Down

0 comments on commit 4abb7d6

Please sign in to comment.