-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworkTracker.scpt
56 lines (45 loc) · 1.6 KB
/
workTracker.scpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var app = Application.currentApplication()
app.includeStandardAdditions = true
var response = app.displayDialog("What's are you working on?", {
defaultAnswer: "",
withIcon: "note",
buttons: ["Cancel", "Continue"],
defaultButton: "Continue",
givingUpAfter: 60//sec
})
//app.displayDialog("Hello, " + (response.textReturned) + ".")
var path = Path("/Users/ishani.gupta/dev/TrackerApp/work.txt")
var filestring = path.toString()
var date = new Date();
var wwork = "\n"+ date +" : "+response.textReturned
writeTextToFile(wwork,filestring,false)
function writeTextToFile(text, file, overwriteExistingContent) {
try {
// Convert the file to a string
var fileString = file.toString()
// Open the file for writing
var openedFile = app.openForAccess(Path(fileString), { writePermission: true })
// Clear the file if content should be overwritten
if (overwriteExistingContent) {
app.setEof(openedFile, { to: 0 })
}
// Write the new content to the file
app.write(text, { to: openedFile, startingAt: app.getEof(openedFile) })
// Close the file
app.closeAccess(openedFile)
// Return a boolean indicating that writing was successful
return true
}
catch(error) {
try {
// Close the file
app.closeAccess(file)
}
catch(error) {
// Report the error is closing failed
console.log(`Couldn't close file: ${error}`)
}
// Return a boolean indicating that writing was successful
return false
}
}