Supportvragen Mac > Programmeren in bijvoorbeeld C(++), Cocoa, Java, BASIC, en Swift

Simpel script nodig tussen CRM applicatie en VoIP software

(1/3) > >>

Cenobyte:
Ik heb eigenlijk voor een zelf ontwikkelde CRM applicatie een simpel script nodig die een brug vormt tussen mijn CRM applicatie en onze VOIP software. Ik heb een script gemaakt, maar krijg het niet werkend.

Als onze telefoon rinkelt kan ik onze VOIP software een commando laten uitvoeren met het telefoonnummer als argument erachter, bijvoorbeeld: GEEFDOOR %telefoonnummer%. Op dit moment is GEEFDOOR een klein programma dat het telefoonnummer in een tekstbestand wegschrijft zodat mijn CRM applicatie dit nummer op kan pakken en aan de gebruiker de erbij behorende NAW gegevens toont. Op dit moment is GEEFDOOR een veel te zware app (gecompileerd 17MB groot) die dan opstart, het telefoonnummer als tekstbestand wegschrijft en daarna meteen sluit. De app loopt echter regelmatig vast/sluit niet af waardoor het systeem dan stopt met werken totdat je de app geforceerd afsluit.

Mijn idee was dan ook om i.p.v. de GEEFDOOR app een simpel AppleScript te schrijven. Dit is gelukt en in theorie werkt het, maar in de praktijk niet. Blijkbaar pakt AppleScript wel externe argumenten aan, maar alleen als het als script wordt uitgevoerd. Zodra ik het script compileer tot app, werkt dit niet meer. En ik kan het script vanuit de VOIP software alleen aanroepen als app, niet als script.  :dontgetit:

Iemand een idee/oplossing hiervoor?


--- Code: ---use scripting additions
on run args
set the text item delimiters to linefeed
try
set theArgs to quoted form of args as text
on error
set theArgs to "error"
end try
set this_story to theArgs & return & ((current date) as string) & return
set theFile to ((("Macintosh HD:Users:mariovanginneken:Library:Application Support:Comos:") as string) & "wieheeftgebeld.txt")
writeTextToFile(this_story, theFile, true)
end run

on writeTextToFile(theText, theFile, overwriteExistingContent)
try

-- Convert the file to a string
set theFile to theFile as string

-- Open the file for writing
set theOpenedFile to open for access file theFile with write permission

-- Clear the file if content should be overwritten
if overwriteExistingContent is true then set eof of theOpenedFile to 0

-- Write the new content to the file
write theText to theOpenedFile starting at eof

-- Close the file
close access theOpenedFile

-- Return a boolean indicating that writing was successful
return true

-- Handle a write error
on error

-- Close the file
try
close access file theFile
end try

-- Return a boolean indicating that writing failed
return false
end try
end writeTextToFile


--- Einde van code ---

Jakko W:

--- Code: ---echo "%telefoonnummer%" > "/Users/mariovanginneken/Library/Application Support/Comos/wieheeftgebeld.txt"
--- Einde van code ---

Aangenomen dat de software die dit aanroept, %telefoonnummer% vervangt door het nummer, schrijft dit commando het nummer naar het bestand.

Daarbij wordt wel elke keer het bestand overschreven, dus er staat nooit meer dan één nummer in. Wil je ook oude nummers behouden, vervang dan > door >> — daarmee wordt elk nummer op een nieuwe regel in het bestand gezet.

Cenobyte:
Ik had die methode ook al geprobeerd inderdaad en vanuit Terminal werkt die, maar het probleem is dat de VOIP software volgens mij alleen een applicatie toestaat en daarbij een argument. Ik heb al ECHO als applicatie en de rest van de regel als argument geprobeerd maar daar trapt ie niet in....

mcmt:
Volgens deze link kan je de argumenten opvragen via NSProcessInfo.

Cenobyte:
Bedankt, dat werkt inderdaad. Hij haalt nu als app wel de argumenten mee  :worship:
Pff, ik zit er volgens mij erg dicht tegenaan, maar krijg hem toch niet werkend, blijft een "false" geven in de writeTextToFile...  :shocked:

Deze heb ik nu (en ja, veel onnodige string transfers  :happy: ):


--- Code: ---use framework "Foundation"
use scripting additions

on run
set the text item delimiters to linefeed
set arguments to (current application's NSProcessInfo's processInfo's arguments) as list
if first item of arguments contains "osascript" then set arguments to rest of arguments -- skip osascript path
if (count arguments) is 1 then set end of arguments to "no arguments"
repeat with anItem in rest of arguments -- skip the main executable path

set theArgs to quoted form of anItem as text
set this_story to theArgs & return & ((current date) as string) & return
set theFile to (path to home folder as text) & "Library:Application Support:Comos:wieheeft1.txt"
writeTextToFile(this_story, theFile, true)
--display dialog this_story
--display dialog theFile

end repeat
# osascript still returns the last result
end run

on writeTextToFile(theText, theFile, overwriteExistingContent)
try

-- Convert the file to a string
set theFile to theFile as string

-- Open the file for writing
set theOpenedFile to open for access file theFile with write permission

-- Clear the file if content should be overwritten
if overwriteExistingContent is true then set eof of theOpenedFile to 0

-- Write the new content to the file
write theText to theOpenedFile starting at eof

-- Close the file
close access theOpenedFile

-- Return a boolean indicating that writing was successful
return true

-- Handle a write error
on error

-- Close the file
try
close access file theFile
end try

-- Return a boolean indicating that writing failed
return false
end try
end writeTextToFile


--- Einde van code ---

Navigatie

[0] Berichtenindex

[#] Volgende pagina

Naar de volledige versie